Configure all Test tasks properly (#3552)

Also configure test tasks that are created (in the build file, or
in other plugins) after the quarkus plugin is applied.
This commit is contained in:
Jesper Skov
2020-02-01 21:41:28 +01:00
parent 8d9665acf0
commit d76978ad9e
3 changed files with 60 additions and 2 deletions

View File

@@ -0,0 +1,47 @@
package io.quarkus.gradle;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Path;
import org.gradle.testkit.runner.BuildResult;
import org.gradle.testkit.runner.GradleRunner;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
public class TaskDependenciesFunctionalTest {
@TempDir
Path projectDir;
/**
* Ensure that all Test tasks depend on the task
* QuarkusTestConfig
* This should include Test tasks created after the
* plugin is applied (such as acceptTest in this test).
*/
@Test
public void shouldMakeTestTasksDependOnQuarkusTestConfig() throws IOException {
createBuildFile();
BuildResult build = GradleRunner.create()
.withProjectDir(projectDir.toFile())
.withArguments("-m", "acceptTest")
.withPluginClasspath()
.build();
assertThat(build.getOutput()).contains(":quarkusTestConfig SKIPPED");
}
private void createBuildFile() throws IOException {
Path buildFile = projectDir.resolve("build.gradle");
try (InputStream is = getClass().getResourceAsStream("/TaskDependenciesFunctionalTest.gradle");
BufferedInputStream bis = new BufferedInputStream(is)) {
Files.copy(bis, buildFile);
}
}
}

View File

@@ -0,0 +1,7 @@
plugins {
id 'java'
id 'io.quarkus'
}
task acceptTest(type: Test) {
}

View File

@@ -1,6 +1,7 @@
package io.quarkus.gradle;
import java.util.Collections;
import java.util.function.Consumer;
import org.gradle.api.GradleException;
import org.gradle.api.Plugin;
@@ -104,12 +105,15 @@ public class QuarkusPlugin implements Plugin<Project> {
Task testNative = tasks.create(TEST_NATIVE_TASK_NAME, QuarkusTestNative.class);
testNative.dependsOn(buildNative);
testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName(JavaPlugin.TEST_TASK_NAME)));
tasks.withType(Test.class).forEach(t -> {
Consumer<Test> configureTestTask = t -> {
// Quarkus test configuration task which should be executed before any Quarkus test
t.dependsOn(quarkusTestConfig);
// also make each task use the JUnit platform since it's the only supported test environment
t.useJUnitPlatform();
});
};
tasks.withType(Test.class).forEach(configureTestTask);
tasks.withType(Test.class).whenTaskAdded(t -> configureTestTask.accept(t));
});
}