Skip to content

Commit

Permalink
Add support for parallel JUnit execution to speed up builds.
Browse files Browse the repository at this point in the history
  • Loading branch information
david-waltermire committed Jan 4, 2025
1 parent 98f3d59 commit 2a19d84
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import org.junit.jupiter.api.BeforeAll;
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.ExecutionMode;

import java.util.LinkedList;
import java.util.List;
Expand All @@ -25,6 +27,7 @@
* Logging solution based on
* https://stackoverflow.com/questions/24205093/how-to-create-a-custom-appender-in-log4j2.
*/
@Execution(value = ExecutionMode.SAME_THREAD, reason = "Log capturing needs to be single threaded")
class ExitCodeTest {
private static MockedAppender mockedAppender;
private static Logger logger;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import gov.nist.secauto.metaschema.cli.processor.ExitStatus;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
Expand All @@ -28,6 +30,7 @@
/**
* Unit test for simple CLI.
*/
@Execution(value = ExecutionMode.SAME_THREAD, reason = "Log capturing needs to be single threaded")
public class CLITest {
private static final ExitCode NO_EXCEPTION_CLASS = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
import gov.nist.secauto.metaschema.cli.CLI;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;

import nl.altindag.log.LogCaptor;

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

@Test
Expand Down
31 changes: 27 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -690,16 +690,39 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<dependencies>
<dependency>
<groupId>me.fabriciorby</groupId>
<artifactId>maven-surefire-junit5-tree-reporter</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<configuration>
<forkCount>1.5C</forkCount>
<reuseForks>true</reuseForks>
<excludedEnvironmentVariables>
<excludedEnvironmentVariable>JAVA_TOOL_OPTIONS</excludedEnvironmentVariable>
</excludedEnvironmentVariables>
<!-- Use of TCP to transmit events to the plugin -->
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
<useModulePath>false</useModulePath>
<redirectTestOutputToFile>true</redirectTestOutputToFile>
<!-- fork configuration -->
<forkCount>1.5C</forkCount>
<reuseForks>true</reuseForks>
<!-- Use of TCP to transmit events to the plugin -->
<forkNode implementation="org.apache.maven.plugin.surefire.extensions.SurefireForkNodeFactory" />
<!-- Junit5 parallel configuration -->
<properties>
<configurationParameters>
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = concurrent
</configurationParameters>
</properties>
<!-- tree reporter configuration -->
<reportFormat>plain</reportFormat>
<consoleOutputReporter>
<disable>true</disable>
</consoleOutputReporter>
<statelessTestsetInfoReporter
implementation="org.apache.maven.plugin.surefire.extensions.junit5.JUnit5StatelessTestsetInfoTreeReporter">
</statelessTestsetInfoReporter>
</configuration>
</plugin>
<plugin>
Expand Down

0 comments on commit 2a19d84

Please sign in to comment.