我正在编写参数化测试,其中测试类和方法是并行运行的.下面是配置.
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
junit.jupiter.execution.parallel.mode.classes.default = concurrent
junit.jupiter.execution.parallel.config.dynamic.factor = 2
测试片段如下-
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
@ExtendWith(SimpleCallbackListener.class)
public class HelloWorldTest {
private static final Map<String, List<TestData>> testDataMap;
static {
testDataMap = TestsConfigManager.readTestConfig("test-data");
}
private static List<Object[]> data() {
final List<Object[]> testDataList = prepareTestData(testDataMap);
return testDataList;
}
@ParameterizedTest(name = "{index}: {0}")
@MethodSource("data")
@Tag("regression")
public void testMethodName(
final String expected,
final String actual
) {
// test code goes here
}
}
SimpleCallbackListener
的数字如下-
public class SimpleCallbackListener implements BeforeAllCallback, ExtensionContext.Store.CloseableResource {
/**
* gatekeeper to prevent multiple Threads within the same routine
*/
private static final Lock LOCK = new ReentrantLock();
private static boolean started = false;
private Instant startTime;
@Override
public void beforeAll(final ExtensionContext context) {
LOCK.lock();
try {
if (!started) {
startTime = Instant.now();
requireApplicationInitializer();
// The following line registers a callback hook when the root test context is shut down
context.getRoot().getStore(GLOBAL).put(this.getClass().getName(), this);
started = true;
}
} finally {
LOCK.unlock();
}
}
}
问题
此设置导致以下间歇性异常.
org.junit.jupiter.api.extension.ParameterResolutionException: No ParameterResolver registered for parameter ... in method ...
at java.base@17.0.7/java.util.concurrent.RecursiveAction.exec(RecursiveAction.java:194)
at java.base@17.0.7/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.base@17.0.7/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.base@17.0.7/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.base@17.0.7/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.base@17.0.7/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
查看了建议的答案-
- https://stackoverflow.com/questions/65934665/why-do-i-have-parameterresolutionexception-when-i-dont-even-use-parametrized-tehttps://stackoverflow.com/questions/65934665/why-do-i-have-parameterresolutionexception-when-i-dont-even-use-parametrized-te个
- Junit 5 - No ParameterResolver registered for parameter个