Because a new startup thread is equivalent to executing a method asynchronously, it is difficult to execute in unit tests.
After searching for data, there is a groboutils tool that enables multithreaded testing, http://groboutils.sourceforge.net/
A simple example fragment:
@Test public
void Grobotest () throws Throwable {
//Constructs a runner
testrunnable runner = new Testrunnable () {
@Override public
void Runtest () throws Throwable {
//test content
System.out.println (Thread.CurrentThread (). GetName ());
}
;
int runnercount = +;
Rnner array, how many you want to be in concurrency.
testrunnable[] trs = new Testrunnable[runnercount];
for (int i = 0; i < Runnercount; i++) {
trs[i] = runner;
}
Runner for executing multithreaded test cases, passing an array of the previously defined single runner into
multithreadedtestrunner mttr = new Multithreadedtestrunner (TRS);
Develop concurrent execution of content defined in the array
mttr.runtestrunnables ();
}