Framework for Unittests for multithreading in Java

What framework would you recommend for writing unit tests for multi-threaded code in Java? For example, when you have a program that needs to execute a bunch of threads with several valid execution paths and some excluded paths (for example, "executable block 1, 2 and 3 can work in parallel, at least two should be executed in parallel, and 4 should always work after 3 ").

+8
java multithreading concurrency unit-testing
source share
4 answers

I suggest reading JUnit @Rule to use them for concurrency tests.

+3
source share

I recommend ContiPerf2 , as it is a very easy to use environment. Although I do not think that this will provide an opportunity to declare execution patterns or something like that.

+2
source share

You can use JUnit parameterized tests as described here: http://junit.org/junit/javadoc/4.5/org/junit/runners/Parameterized.html

But you will need to program the flow logic yourself, for example, using different thread pools.

You can take a look at pathfinder (http://javapathfinder.sourceforge.net/) if you want to prove that your code is thread safe.

+1
source share

This thread describes some common approaches to testing parallel code.

Designing a Test Class for a Custom Barrier

For specific frameworks, tempus-fugit contains some JUnit rules for parallel operation , but as suggested above, you are likely to include more logic.

+1
source share

All Articles