Skip to content

Commit 2a19d84

Browse files
Add support for parallel JUnit execution to speed up builds.
1 parent 98f3d59 commit 2a19d84

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

cli-processor/src/test/java/gov/nist/secauto/metaschema/cli/processor/ExitCodeTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import org.junit.jupiter.api.BeforeAll;
1616
import org.junit.jupiter.api.BeforeEach;
1717
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.parallel.Execution;
19+
import org.junit.jupiter.api.parallel.ExecutionMode;
1820

1921
import java.util.LinkedList;
2022
import java.util.List;
@@ -25,6 +27,7 @@
2527
* Logging solution based on
2628
* https://stackoverflow.com/questions/24205093/how-to-create-a-custom-appender-in-log4j2.
2729
*/
30+
@Execution(value = ExecutionMode.SAME_THREAD, reason = "Log capturing needs to be single threaded")
2831
class ExitCodeTest {
2932
private static MockedAppender mockedAppender;
3033
private static Logger logger;

metaschema-cli/src/test/java/gov/nist/secauto/metaschema/cli/CLITest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414
import gov.nist.secauto.metaschema.cli.processor.ExitStatus;
1515

1616
import org.junit.jupiter.api.Test;
17+
import org.junit.jupiter.api.parallel.Execution;
18+
import org.junit.jupiter.api.parallel.ExecutionMode;
1719
import org.junit.jupiter.params.ParameterizedTest;
1820
import org.junit.jupiter.params.provider.Arguments;
1921
import org.junit.jupiter.params.provider.MethodSource;
@@ -28,6 +30,7 @@
2830
/**
2931
* Unit test for simple CLI.
3032
*/
33+
@Execution(value = ExecutionMode.SAME_THREAD, reason = "Log capturing needs to be single threaded")
3134
public class CLITest {
3235
private static final ExitCode NO_EXCEPTION_CLASS = null;
3336

metaschema-cli/src/test/java/gov/nist/secauto/metaschema/cli/commands/metapath/EvaluateMetapathSubCommandTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
import gov.nist.secauto.metaschema.cli.CLI;
1111

1212
import org.junit.jupiter.api.Test;
13+
import org.junit.jupiter.api.parallel.Execution;
14+
import org.junit.jupiter.api.parallel.ExecutionMode;
1315

1416
import nl.altindag.log.LogCaptor;
1517

18+
@Execution(value = ExecutionMode.SAME_THREAD, reason = "Log capturing needs to be single threaded")
1619
class EvaluateMetapathSubCommandTest {
1720

1821
@Test

pom.xml

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -690,16 +690,39 @@
690690
<plugin>
691691
<groupId>org.apache.maven.plugins</groupId>
692692
<artifactId>maven-surefire-plugin</artifactId>
693+
<dependencies>
694+
<dependency>
695+
<groupId>me.fabriciorby</groupId>
696+
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
697+
<version>1.4.0</version>
698+
</dependency>
699+
</dependencies>
693700
<configuration>
694-
<forkCount>1.5C</forkCount>
695-
<reuseForks>true</reuseForks>
696701
<excludedEnvironmentVariables>
697702
<excludedEnvironmentVariable>JAVA_TOOL_OPTIONS</excludedEnvironmentVariable>
698703
</excludedEnvironmentVariables>
699-
<!-- Use of TCP to transmit events to the plugin -->
700-
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
701704
<useModulePath>false</useModulePath>
702705
<redirectTestOutputToFile>true</redirectTestOutputToFile>
706+
<!-- fork configuration -->
707+
<forkCount>1.5C</forkCount>
708+
<reuseForks>true</reuseForks>
709+
<!-- Use of TCP to transmit events to the plugin -->
710+
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
711+
<!-- Junit5 parallel configuration -->
712+
<properties>
713+
<configurationParameters>
714+
junit.jupiter.execution.parallel.enabled = true
715+
junit.jupiter.execution.parallel.mode.default = concurrent
716+
</configurationParameters>
717+
</properties>
718+
<!-- tree reporter configuration -->
719+
<reportFormat>plain</reportFormat>
720+
<consoleOutputReporter>
721+
<disable>true</disable>
722+
</consoleOutputReporter>
723+
<statelessTestsetInfoReporter
724+
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
725+
</statelessTestsetInfoReporter>
703726
</configuration>
704727
</plugin>
705728
<plugin>

0 commit comments

Comments
 (0)