Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda