Home Unit testing Rxjava observables that have a delay
Reply: 0

Unit testing Rxjava observables that have a delay

user753 Published in March 19, 2018, 4:35 pm

I want to be able to unit test an Observable that has a delayed emission, but without actually waiting for the delay time. Is there a way to do this?

I'm currently using a CountDownHatch to delay the assert, and that works fine, but increases the test run time.


val myObservable: PublishSubject<Boolean> = PublishSubject.create<Boolean>()
fun myObservable(): Observable<Boolean> = myObservable.delay(3, TimeUnit.SECONDS)

fun testMyObservable() {
    val testObservable = myObservable().test()

    // val lock = CountDownLatch(1)
    // lock.await(3100, TimeUnit.MILLISECONDS)
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.301616 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO