How to write multi-threaded unit tests? How to write multi-threaded unit tests? multithreading multithreading

How to write multi-threaded unit tests?


There is ConTest, and also GroboUtils.

I've used GroboUtils many years ago, and it did the job. ConTest is newer, and would be my preferred starting point now, since rather than just relying on trial and error, the instrumentation forces specific interleavings of the threads, providing a deterministic test. In contrast, GroboUtils MultiThreadedTestRunner simply runs the tests and hopes the scheduler produces an interleaving that causes the thread bug to appear.

EDIT: See also ConcuTest which also forces interleavings and is free.


Just using the concurrency libraries would simplify your code. You can turn your boiler plate code into one method.

Something like

public static void runAll(int times, Runnable... tests) {}