Yeah, most testing frameworks are
firmly anchored in the 90s/00s and seem not to have even noticed
that a lot of stuff is async these days. I have yet to find a
decent Java test framework that can handle async tests out of the
box. (Hint: Maybe there is room in the market for a new test
framework?)
In Vert.x 3.0 we solve this by having our test base class which
has a few useful methods for async tests, so you can do stuff
like:
https://github.com/eclipse/vert.x/blob/master/vertx-core/src/test/java/io/vertx/test/core/AsyncTestBaseTest.java#L105
I.e. you can call assertXXX(...) and fail(...) on threads other
than the main test thread. You can't do this in normal JUnit as
Junit assertXXX calls throw assertException which isn't caught by
Junit unless it's on the Junit thread.
So we provide our own version of each assertXXX which captures
whether the assert succeeded or passed. Then when your test is
complete you call testComplete(), and you call await() at the end
of your test to stop it exiting.
When the test is complete, the JUnit thread on waiting on await()
wakes up and if any asserts have failed it will rethrow the
AssertException this time from the main thread.
Anyway.... all this stuff should be in a real test framework.