Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JUnit5 doesn't allow to run parameterized test with @MethodSource in parallel and other test sequentially #3373

Open
gl-khimin opened this issue Jun 26, 2023 · 3 comments

Comments

@gl-khimin
Copy link

How to run parameterized JUnit test which retrieves data from @MethodSource in parallel way ?

private static Stream scenarioPathList2() {
return Stream.of(
Arguments.of("example-data/file1.csv"),
Arguments.of("example-data/file2.csv"));
}

@ParameterizedTest(name = "Parallel Test1 {0}")
@MethodSource({"scenarioPathList"})
@Execution(CONCURRENT)
public void parallelTest1(String scenarioPath) {
    System.out.println("Test1 time: " +LocalDateTime.now());
    executeScenario(scenarioPath);
}

One way to do it is to run only one test in class parallely I found global configurations: junit.jupiter.execution.parallel.mode.default = same_thread / run tests in class parallely junit.jupiter.execution.parallel.mode.classes.default = same_thread / tests classes parallely junit.jupiter.execution.parallel.enabled=true

image

@gl-khimin
Copy link
Author

@marcphilipp does JUnit 5 has the opportunity to run tests from @MethodSource parallely ?

@sormuras
Copy link
Member

sormuras commented Jun 26, 2023

Edit(h) deleted a screenshot of "Writing Tests" / "Parallel Execution" section from the User Guide.

https://junit.org/junit5/docs/current/user-guide/#writing-tests-parallel-execution

@gl-khimin
Copy link
Author

@sormuras thanks for the reference, but test with method source feels it as separate test. When I run A.test1[1] and A.test[2] and A.test2[1] and A.test2[2] it can run crossing like A.test1[1] and A.test2[1].

How to be sure that test with all data run and after that move to another test ?

@TestMethodOrder(MethodOrderer.OrderAnnotation.class) doesn't help me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants