views:

35

answers:

3

Has anyone got any advice or know of any frameworks for unit-testing of multithreaded applications?

+1  A: 

Do not test multithreaded applications. Refactor the code to remove coupling between work that is done in different threads. Then test it separately.

Boris Pavlović
A: 

Typically you don't unit test the concurrency of multi threaded applications as the unit tests aren't dependable and reproducible - because of the nature of concurrency bugs its not generally possible to write unit tests that consistently either fail or succeed, and so unit tests of concurrent code generally don't make very useful unit tests.

Instead you unit test each single threaded components of your application as normal and rely on load testing sessions to identify concurrency issues.

That said, there are some experimental load testing frameworks for testing concurrent applications, such as Microsoft CHESS - CHESS repeatedly runs a given unit test and systematically explores every possible interleaving of a concurrent test. This makes your unit tests dependable and reproducible.

For the moment however CHESS is still experimental (and probably not usable with the JVM) - for now stick with load testing to weed out concurrency issues.

Kragen