Vladimir
Vladimir

Reputation: 13153

Unit-testing multithreaded applications

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

Upvotes: 7

Views: 14000

Answers (3)

Boris Pavlović
Boris Pavlović

Reputation: 64622

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

Upvotes: 6

Justin
Justin

Reputation: 86729

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.

Upvotes: 5

Related Questions