Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

175
Views
How to write unit tests for continuous Combine publisher without using wait(for:timeout:)?

Imagine, we have a sut as a publisher which publishes values continuously and never finishes. On change of some input (ex: we change some mocked @Published property which our sut depends on), it emits an event.

We're collecting these events in results array and then checking if there is an exact expected number of events, not less and not more.

The problem is - how to check there are no more events after what we expect to be emitted? Without wait method we don't know when it's time to check the results array.

wait will work but it feels for me like a crutch for Combine. Because the good unit tests should be fast (see F.I.R.S.T principles of unit testing). And these waits looks more like anti-pattern.

I also couldn't find an Apple's recommendation on this.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You need a test scheduler, which is basically a virtual time scheduler that will let you control when the time-based events will be published. So for example you can fire all the events at once. Combine does not have build-in a test scheduler, but you can use an open source test scheduler called Entwine

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!