Skip to content

Commit

Permalink
⚡️ Run Unit Tests Concurrently
Browse files Browse the repository at this point in the history
By default, all unit tests run concurrently. We opt-out of this behavior in cases where this is an issue.
  • Loading branch information
gilday committed Jun 25, 2024
1 parent 560dbfc commit fe467bf
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,21 +68,23 @@ default Stream<DynamicTest> generateTestCases(@TempDir final Path tmpDir) throws
.toList();

ThrowingConsumer<Path> testExecutor =
path ->
verifyCodemod(
metadata.codemodType(),
metadata.renameTestFile(),
tmpDir,
testResourceDir,
path,
dependencies,
projectProviders,
metadata.doRetransformTest(),
metadata.expectingFixesAtLines(),
metadata.expectingFailedFixesAtLines(),
metadata.sonarIssuesJsonFiles(),
metadata.sonarHotspotsJsonFiles());

path -> {
// create a new temporary directory for each test case
final var tmp = Files.createTempDirectory(tmpDir, "test-case-");
verifyCodemod(
metadata.codemodType(),
metadata.renameTestFile(),
tmp,
testResourceDir,
path,
dependencies,
projectProviders,
metadata.doRetransformTest(),
metadata.expectingFixesAtLines(),
metadata.expectingFailedFixesAtLines(),
metadata.sonarIssuesJsonFiles(),
metadata.sonarHotspotsJsonFiles());
};
return DynamicTest.stream(inputStream, displayNameGenerator, testExecutor);
}

Expand Down
17 changes: 15 additions & 2 deletions gradle/build-plugins/src/main/kotlin/io.codemodder.java.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,19 @@ spotless {
}
}

tasks.withType(Test::class) {
useJUnitPlatform()
testing {
@Suppress("UnstableApiUsage")
suites {
val test by getting(JvmTestSuite::class) {
useJUnitJupiter()
targets {
all {
testTask.configure {
systemProperty("junit.jupiter.execution.parallel.enabled", "true")
systemProperty("junit.jupiter.execution.parallel.mode.default", "concurrent")
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.codemodder.plugins.maven;

import static org.assertj.core.api.Assertions.*;
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
Expand All @@ -20,6 +21,7 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.junit.jupiter.api.parallel.Execution;
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 tests for {@link MavenProvider}. We bend over backwards here not to test the pom-operator
* types.
*/
@Execution(SAME_THREAD)
final class MavenProviderTest {

private static class TestPomModifier implements MavenProvider.PomModifier {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
package io.codemodder.plugins.maven.operator;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.parallel.ExecutionMode.SAME_THREAD;

import java.io.*;
import java.util.*;
import org.apache.commons.lang3.SystemUtils;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

@Execution(SAME_THREAD)
final class RemoteRepositoriesIntegrationTest {
private static final Logger LOGGER =
LoggerFactory.getLogger(RemoteRepositoriesIntegrationTest.class);
Expand Down

0 comments on commit fe467bf

Please sign in to comment.