Here you are. You just finished writing your brand new application using the newest technologies from Google and Jetbrains, and now time has come to test it. 👻

You start googling around, and hopefully, you came to the official coroutines documentation, then start writing your first unit test, something like this:

Too eazy 😎

Then, you want to start testing something more complicated. You are using obviously Room as your database and now you want to test your shiny Dao that exposes your reactive Flow.

And 💥💥 BOOM 💥💥

java.lang.IllegalStateException: This job has not completed yet

Why? Why does this happen? Why does this happen to ME?

The underline Flow has never been closed because it’s still waiting (like FOREVER) to emit more values every time the table content changes, but you want to get all the values, and you want them RIGHT NOW. But the coroutine test job has better things to do!

Now, let’s get cereal for a moment.

My solution

So, inspired by RxJava TestObserver, I wrote this library that offers a lot of handy assertions, and above all, allows you to test against hot/infinite streams. Here’s an example.

Hurray!!

You can find the repository on GitHub and start using it right now!

Here’s the list of all available assertions.

Feel free to open any PR or Issues.

Updates

v1.4.0

Fixed the problems with RendezvousChannel and BufferedChannel . Now every channel can be tested as it should be ❤️

v1.3.0

Converted library from Android to JVM, so it can be used in any project

v1.1.0

RendezvousChannel and BufferedChannel with small buffers can not be tested