Multithreaded Unit Testing Applications

Has anyone received any recommendations or knew about any framework for unit testing multi-threaded applications?

+4
source share
4 answers
+3
source

Do not test multithreaded applications. Code refactoring to remove the connection between work performed on different threads. Then check it separately.

+4
source

As a rule, you do not use unit test concurrency of multi-threaded applications, since unit tests are not reliable and reproducible - due to the nature of concurrency errors, it is usually impossible to write unit tests that are sequentially either fail or successful, and therefore unit tests of parallel code are usually don't do very useful unit tests.

Instead, you unit test each individual component of your application as usual and rely on load testing sessions to identify concurrency issues.

However, there are some experimental load testing platforms for testing parallel applications, such as Microsoft CHESS - CHESS repeatedly runs a given unit test and systematically examines every possible parallel test rotation. This makes your unit tests reliable and repeatable.

At the moment, CHESS is still experimental (and probably not applicable to the JVM) - now stick with load testing to screen out concurrency problems.

+2
source

There is nothing wrong with testing multi-threaded code, especially if threads are the point of code that you are testing. A general approach for testing a thread / asynchronous code is to block the main test thread, capture any failed statements from other threads, unlock the main test thread, and reorganize any failures. ConcurrentUnit takes care of most of this for you:

final Waiter waiter = new Waiter(); new Thread(() -> { doSomeWork(); waiter.assertTrue(true); waiter.resume(); }).start(); // Wait for resume() to be called waiter.await(1000); 
+1
source

All Articles