forked from junit-team/junit5
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce support for parallel test execution
This commit adds opt-in support for parallel test execution and capturing output to `System.out` and `System.err`. Both features are disabled by default but can be enabled and configured using configuration parameters. The implementation is based on the Fork/Join Framework and designed to be reusable by other test engines that extend HierarchicalTestEngine. The Jupiter API provides annotations to declare which shared resources a test needs to access and in which way. Moreover, the execution mode of a test can be influenced. In addition, a number of TestExecutionListeners have been made thread-safe. The documentation subproject is now configured to execute tests in parallel. All other subprojects will have to wait as Gradle currently blows up when used with parallel test execution. Resolves junit-team#60. Closes junit-team#1461. Co-authored-by: Leonard Brünings <[email protected]> Co-authored-by: Christian Stein <[email protected]>
- Loading branch information
Showing
71 changed files
with
4,084 additions
and
258 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
documentation/src/test/java/example/SharedResourcesDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
/* | ||
* Copyright 2015-2018 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package example; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNull; | ||
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; | ||
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ; | ||
import static org.junit.jupiter.api.parallel.ResourceAccessMode.READ_WRITE; | ||
import static org.junit.jupiter.api.parallel.Resources.SYSTEM_PROPERTIES; | ||
|
||
import java.util.Properties; | ||
|
||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
import org.junit.jupiter.api.parallel.ResourceLock; | ||
|
||
// tag::user_guide[] | ||
@Execution(CONCURRENT) | ||
class SharedResourcesDemo { | ||
|
||
private Properties backup; | ||
|
||
@BeforeEach | ||
void backup() { | ||
backup = new Properties(); | ||
backup.putAll(System.getProperties()); | ||
} | ||
|
||
@AfterEach | ||
void restore() { | ||
System.setProperties(backup); | ||
} | ||
|
||
@Test | ||
@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ) | ||
void customPropertyIsNotSetByDefault() { | ||
assertNull(System.getProperty("my.prop")); | ||
} | ||
|
||
@Test | ||
@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ_WRITE) | ||
void canSetCustomPropertyToFoo() { | ||
System.setProperty("my.prop", "foo"); | ||
assertEquals("foo", System.getProperty("my.prop")); | ||
} | ||
|
||
@Test | ||
@ResourceLock(value = SYSTEM_PROPERTIES, mode = READ_WRITE) | ||
void canSetCustomPropertyToBar() { | ||
System.setProperty("my.prop", "bar"); | ||
assertEquals("bar", System.getProperty("my.prop")); | ||
} | ||
} | ||
// end::user_guide[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
/* | ||
* Copyright 2015-2018 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v2.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v20.html | ||
*/ | ||
|
||
package example; | ||
|
||
// tag::user_guide[] | ||
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD; | ||
|
||
import java.util.stream.IntStream; | ||
|
||
import org.junit.jupiter.api.Disabled; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
|
||
@Disabled | ||
class SlowTests { | ||
|
||
@Execution(SAME_THREAD) | ||
@Test | ||
void a() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void b() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void c() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void d() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void e() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void f() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void g() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void h() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void i() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void j() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void k() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void l() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void m() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void n() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void o() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void p() { | ||
foo(); | ||
} | ||
|
||
@Execution(SAME_THREAD) | ||
@Test | ||
void q() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void r() { | ||
foo(); | ||
} | ||
|
||
@Test | ||
void s() { | ||
foo(); | ||
} | ||
|
||
private void foo() { | ||
IntStream.range(1, 100_000_000).mapToDouble(i -> Math.pow(i, i)).map(Math::sqrt).max(); | ||
} | ||
} | ||
// end::user_guide[] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
junit.jupiter.execution.parallel.enabled=true | ||
junit.jupiter.execution.parallel.config.strategy=fixed | ||
junit.jupiter.execution.parallel.config.fixed.parallelism=6 |
Oops, something went wrong.