package com.junit5.dynamictest_parallel;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import java.util.Arrays;
import java.util.Collection;
@Execution(ExecutionMode.CONCURRENT) //方法注解,类注解
public class DynaimcParallelTest {
// @Execution(ExecutionMode.CONCURRENT)
@TestFactory
Collection<DynamicTest> parallelTest1() {
DynamicTest dynamicTest1 = DynamicTest.dynamicTest("1st parallel", () -> {
System.out.println(Thread.currentThread().getName() + "---1st parallel");
});
DynamicTest dynamicTest2 = DynamicTest.dynamicTest("2st parallel", () -> {
System.out.println(Thread.currentThread().getName() + "---2st parallel");
});
DynamicTest dynamicTest3 = DynamicTest.dynamicTest("3st parallel", () -> {
System.out.println(Thread.currentThread().getName() + "---3st parallel");
});
return Arrays.asList(dynamicTest1, dynamicTest2, dynamicTest3);
}
@Execution(ExecutionMode.SAME_THREAD)
@TestFactory
Collection<DynamicTest> parallelTest2() {
DynamicTest dynamicTest1 = DynamicTest.dynamicTest("SAME_THREAD1st parallel", () -> {
System.out.println(Thread.currentThread().getName() + "---SAME_THREAD1st parallel");
});
DynamicTest dynamicTest2 = DynamicTest.dynamicTest("SAME_THREAD2st parallel", () -> {
System.out.println(Thread.currentThread().getName() + "---SAME_THREAD2st parallel");
});
DynamicTest dynamicTest3 = DynamicTest.dynamicTest("SAME_THREAD3st parallel", () -> {
System.out.println(Thread.currentThread().getName() + "---SAME_THREAD3st parallel");
});
return Arrays.asList(dynamicTest1, dynamicTest2, dynamicTest3);
}
}
评论