From 958b29f769a96c72ad6cfd8934819de91b849581 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 16 Oct 2019 11:07:40 +0300 Subject: [PATCH 1/4] Enable JUnit 5 in generate gradle projects --- .../templates/basic-rest/java/build.gradle-template.ftl | 5 +++++ .../templates/basic-rest/kotlin/build.gradle-template.ftl | 5 +++++ .../templates/basic-rest/scala/build.gradle-template.ftl | 6 ++++++ 3 files changed, 16 insertions(+) diff --git a/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl index a6ec01770ba48..1cb1e962a8e62 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl @@ -35,5 +35,10 @@ compileJava { options.compilerArgs << '-parameters' } +test { + useJUnitPlatform() + exclude '**/Native*' +} + diff --git a/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl index 48429e48be7ee..62ca99e4fa5ba 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl @@ -32,6 +32,11 @@ dependencies { group '${project_groupId}' version '${project_version}' +test { + useJUnitPlatform() + exclude '**/Native*' +} + quarkus { setOutputDirectory("$projectDir/build/classes/kotlin/main") } diff --git a/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl index c93f170bd7233..303dcaa00debd 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl @@ -30,3 +30,9 @@ dependencies { group '${project_groupId}' version '${project_version}' + +test { + useJUnitPlatform() + exclude '**/Native*' +} + From 7155a0ad151cb08bf98b4bc1f38da8072ead9347 Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 16 Oct 2019 11:21:39 +0300 Subject: [PATCH 2/4] Fix gradle documentation around testing --- docs/src/main/asciidoc/gradle-tooling.adoc | 2 ++ docs/src/main/asciidoc/kotlin.adoc | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/src/main/asciidoc/gradle-tooling.adoc b/docs/src/main/asciidoc/gradle-tooling.adoc index 7f3df48660bdd..889c48fdfe6cd 100644 --- a/docs/src/main/asciidoc/gradle-tooling.adoc +++ b/docs/src/main/asciidoc/gradle-tooling.adoc @@ -132,6 +132,7 @@ Quarkus uses Junit5 and to enable it in Gradle we need to add a section to our b ---- test { useJUnitPlatform() + exclude '**/Native*' } ---- @@ -141,6 +142,7 @@ Using the Kotlin DSL, add: ---- tasks.test { useJUnitPlatform() + exclude("**/Native*") } ---- diff --git a/docs/src/main/asciidoc/kotlin.adoc b/docs/src/main/asciidoc/kotlin.adoc index 206395eddfa66..1972d14344312 100644 --- a/docs/src/main/asciidoc/kotlin.adoc +++ b/docs/src/main/asciidoc/kotlin.adoc @@ -282,7 +282,7 @@ tasks { tasks.test { useJUnitPlatform() - exclude '**/Native*' + exclude("**/Native*") } allOpen { // <5> From 20f2ac51f3974124e2bf71dab30f72a38c2860be Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Wed, 16 Oct 2019 14:06:38 +0300 Subject: [PATCH 3/4] Make native tests a separate source set in generated gradle projects --- .../rest/BasicRestProjectGenerator.java | 27 ++++++++++++++-- .../basic-rest/java/build.gradle-template.ftl | 31 ++++++++++++++++++- .../kotlin/build.gradle-template.ftl | 31 ++++++++++++++++++- .../scala/build.gradle-template.ftl | 31 ++++++++++++++++++- .../quarkus/test/common/PathTestHelper.java | 9 ++++++ 5 files changed, 123 insertions(+), 6 deletions(-) diff --git a/devtools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java b/devtools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java index aea7c3c9ada6f..36c2d8da0a55b 100644 --- a/devtools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java +++ b/devtools/common/src/main/java/io/quarkus/generators/rest/BasicRestProjectGenerator.java @@ -56,6 +56,7 @@ private class BasicRestProject { private ProjectWriter writer; private String srcMainPath; private String testMainPath; + private String nativeTestMainPath; private SourceType type; private BasicRestProject(final ProjectWriter writer, final Map parameters) { @@ -76,13 +77,19 @@ private boolean initProject() throws IOException { srcMainPath = writer.mkdirs(type.getSrcDir()); testMainPath = writer.mkdirs(type.getTestSrcDir()); + // for gradle we want to place the native tests in under 'src/native-test/java' + // since gradle's idiomatic way of running integration tests is to create a new source set + if (getBuildTool() == BuildTool.GRADLE) { + nativeTestMainPath = writer.mkdirs(type.getTestSrcDir().replace("test", "native-test")); + } else { + nativeTestMainPath = testMainPath; + } return newProject; } private boolean initBuildTool() throws IOException { - BuildFile buildFileManager = get(BUILD_FILE, null); - BuildTool buildTool = buildFileManager == null ? BuildTool.MAVEN : buildFileManager.getBuildTool(); + BuildTool buildTool = getBuildTool(); context.putIfAbsent(ADDITIONAL_GITIGNORE_ENTRIES, buildTool.getGitIgnoreEntries()); boolean newProject = !writer.exists(buildTool.getDependenciesFile()); if (newProject) { @@ -110,6 +117,11 @@ private boolean initBuildTool() throws IOException { return newProject; } + private BuildTool getBuildTool() { + BuildFile buildFileManager = get(BUILD_FILE, null); + return buildFileManager == null ? BuildTool.MAVEN : buildFileManager.getBuildTool(); + } + private void generate(final String templateName, final Map context, final String outputFilePath, final String resourceType) throws IOException { @@ -176,9 +188,18 @@ private void setupContext() throws IOException { if (packageName != null) { String packageDir = srcMainPath + '/' + packageName.replace('.', '/'); + String originalTestMainPath = testMainPath; String testPackageDir = testMainPath + '/' + packageName.replace('.', '/'); srcMainPath = writer.mkdirs(packageDir); testMainPath = writer.mkdirs(testPackageDir); + + if (!originalTestMainPath.equals(nativeTestMainPath)) { + String nativeTestPackageDir = nativeTestMainPath + '/' + packageName.replace('.', '/'); + nativeTestMainPath = writer.mkdirs(nativeTestPackageDir); + } else { + nativeTestMainPath = testMainPath; + } + } else { throw new NullPointerException("Need a non-null package name"); } @@ -192,7 +213,7 @@ private void createClasses() throws IOException { String extension = type.getExtension(); String classFile = srcMainPath + '/' + className + extension; String testClassFile = testMainPath + '/' + className + "Test" + extension; - String itTestClassFile = testMainPath + '/' + "Native" + className + "IT" + extension; + String itTestClassFile = nativeTestMainPath + '/' + "Native" + className + "IT" + extension; String name = getName(); String srcResourceTemplate = type.getSrcResourceTemplate(name); Object isSpring = context.get(IS_SPRING); diff --git a/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl index 1cb1e962a8e62..6596bc398e527 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl @@ -20,12 +20,29 @@ repositories { mavenCentral() } +sourceSets { + nativeTest { + compileClasspath += sourceSets.main.output + compileClasspath += sourceSets.test.output + runtimeClasspath += sourceSets.main.output + runtimeClasspath += sourceSets.test.output + } +} + +configurations { + nativeTestImplementation.extendsFrom implementation + nativeTestRuntimeOnly.extendsFrom runtimeOnly +} + dependencies { implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}") implementation 'io.quarkus:quarkus-resteasy' testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' + + nativeTestImplementation 'io.quarkus:quarkus-junit5' + nativeTestImplementation 'io.rest-assured:rest-assured' } group '${project_groupId}' @@ -37,8 +54,20 @@ compileJava { test { useJUnitPlatform() - exclude '**/Native*' } +task testNative(type: Test) { + useJUnitPlatform() + description = 'Runs native image tests' + group = 'verification' + + testClassesDirs = sourceSets.nativeTest.output.classesDirs + classpath = sourceSets.nativeTest.runtimeClasspath + shouldRunAfter test +} + +testNative.dependsOn buildNative +check.dependsOn testNative + diff --git a/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl index 62ca99e4fa5ba..3494fb18b9d2d 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl @@ -20,6 +20,20 @@ repositories { mavenCentral() } +sourceSets { + nativeTest { + compileClasspath += sourceSets.main.output + compileClasspath += sourceSets.test.output + runtimeClasspath += sourceSets.main.output + runtimeClasspath += sourceSets.test.output + } +} + +configurations { + nativeTestImplementation.extendsFrom implementation + nativeTestRuntimeOnly.extendsFrom runtimeOnly +} + dependencies { implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}") implementation 'io.quarkus:quarkus-resteasy' @@ -27,6 +41,9 @@ dependencies { testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' + + nativeTestImplementation 'io.quarkus:quarkus-junit5' + nativeTestImplementation 'io.rest-assured:rest-assured' } group '${project_groupId}' @@ -34,9 +51,21 @@ version '${project_version}' test { useJUnitPlatform() - exclude '**/Native*' } +task testNative(type: Test) { + useJUnitPlatform() + description = 'Runs native image tests' + group = 'verification' + + testClassesDirs = sourceSets.nativeTest.output.classesDirs + classpath = sourceSets.nativeTest.runtimeClasspath + shouldRunAfter test +} + +testNative.dependsOn buildNative +check.dependsOn testNative + quarkus { setOutputDirectory("$projectDir/build/classes/kotlin/main") } diff --git a/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl index 303dcaa00debd..beed9cdce922e 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl @@ -20,12 +20,29 @@ repositories { mavenCentral() } +sourceSets { + nativeTest { + compileClasspath += sourceSets.main.output + compileClasspath += sourceSets.test.output + runtimeClasspath += sourceSets.main.output + runtimeClasspath += sourceSets.test.output + } +} + +configurations { + nativeTestImplementation.extendsFrom implementation + nativeTestRuntimeOnly.extendsFrom runtimeOnly +} + dependencies { implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}") implementation 'io.quarkus:quarkus-resteasy' testImplementation 'io.quarkus:quarkus-junit5' testImplementation 'io.rest-assured:rest-assured' + + nativeTestImplementation 'io.quarkus:quarkus-junit5' + nativeTestImplementation 'io.rest-assured:rest-assured' } group '${project_groupId}' @@ -33,6 +50,18 @@ version '${project_version}' test { useJUnitPlatform() - exclude '**/Native*' } +task testNative(type: Test) { + useJUnitPlatform() + description = 'Runs native image tests' + group = 'verification' + + testClassesDirs = sourceSets.nativeTest.output.classesDirs + classpath = sourceSets.nativeTest.runtimeClasspath + shouldRunAfter test +} + +testNative.dependsOn buildNative +check.dependsOn testNative + diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java b/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java index 4dbe0c95a3dec..156e9fcf5801c 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java @@ -21,12 +21,21 @@ public final class PathTestHelper { "bin" + File.separator + "test", "bin" + File.separator + "main"); // gradle + TEST_TO_MAIN_DIR_FRAGMENTS.put( + "classes" + File.separator + "java" + File.separator + "nativeTest", + "classes" + File.separator + "java" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( "classes" + File.separator + "java" + File.separator + "test", "classes" + File.separator + "java" + File.separator + "main"); + TEST_TO_MAIN_DIR_FRAGMENTS.put( + "classes" + File.separator + "kotlin" + File.separator + "nativeTest", + "classes" + File.separator + "kotlin" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( "classes" + File.separator + "kotlin" + File.separator + "test", "classes" + File.separator + "kotlin" + File.separator + "main"); + TEST_TO_MAIN_DIR_FRAGMENTS.put( + "classes" + File.separator + "scala" + File.separator + "nativeTest", + "classes" + File.separator + "scala" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( "classes" + File.separator + "scala" + File.separator + "test", "classes" + File.separator + "scala" + File.separator + "main"); From 44ba9362169c34b96537c2e22ae4c30c6055924c Mon Sep 17 00:00:00 2001 From: Georgios Andrianakis Date: Thu, 17 Oct 2019 10:34:47 +0300 Subject: [PATCH 4/4] Move all test related configuration to Gradle plugin --- .../basic-rest/java/build.gradle-template.ftl | 31 -------------- .../kotlin/build.gradle-template.ftl | 31 -------------- .../scala/build.gradle-template.ftl | 31 -------------- .../java/io/quarkus/gradle/QuarkusPlugin.java | 41 +++++++++++++++++-- .../gradle/tasks/QuarkusTestNative.java | 21 ++++++++++ docs/src/main/asciidoc/gradle-tooling.adoc | 24 ++--------- docs/src/main/asciidoc/kotlin.adoc | 5 --- .../quarkus/test/common/PathTestHelper.java | 6 +-- 8 files changed, 65 insertions(+), 125 deletions(-) create mode 100644 devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusTestNative.java diff --git a/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl index 6596bc398e527..0c3cd23d8385f 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/java/build.gradle-template.ftl @@ -20,20 +20,6 @@ repositories { mavenCentral() } -sourceSets { - nativeTest { - compileClasspath += sourceSets.main.output - compileClasspath += sourceSets.test.output - runtimeClasspath += sourceSets.main.output - runtimeClasspath += sourceSets.test.output - } -} - -configurations { - nativeTestImplementation.extendsFrom implementation - nativeTestRuntimeOnly.extendsFrom runtimeOnly -} - dependencies { implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}") implementation 'io.quarkus:quarkus-resteasy' @@ -52,22 +38,5 @@ compileJava { options.compilerArgs << '-parameters' } -test { - useJUnitPlatform() -} - -task testNative(type: Test) { - useJUnitPlatform() - description = 'Runs native image tests' - group = 'verification' - - testClassesDirs = sourceSets.nativeTest.output.classesDirs - classpath = sourceSets.nativeTest.runtimeClasspath - shouldRunAfter test -} - -testNative.dependsOn buildNative -check.dependsOn testNative - diff --git a/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl index 3494fb18b9d2d..837543fbe6ec7 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/kotlin/build.gradle-template.ftl @@ -20,20 +20,6 @@ repositories { mavenCentral() } -sourceSets { - nativeTest { - compileClasspath += sourceSets.main.output - compileClasspath += sourceSets.test.output - runtimeClasspath += sourceSets.main.output - runtimeClasspath += sourceSets.test.output - } -} - -configurations { - nativeTestImplementation.extendsFrom implementation - nativeTestRuntimeOnly.extendsFrom runtimeOnly -} - dependencies { implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}") implementation 'io.quarkus:quarkus-resteasy' @@ -49,23 +35,6 @@ dependencies { group '${project_groupId}' version '${project_version}' -test { - useJUnitPlatform() -} - -task testNative(type: Test) { - useJUnitPlatform() - description = 'Runs native image tests' - group = 'verification' - - testClassesDirs = sourceSets.nativeTest.output.classesDirs - classpath = sourceSets.nativeTest.runtimeClasspath - shouldRunAfter test -} - -testNative.dependsOn buildNative -check.dependsOn testNative - quarkus { setOutputDirectory("$projectDir/build/classes/kotlin/main") } diff --git a/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl b/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl index beed9cdce922e..a46c098e91d7a 100644 --- a/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl +++ b/devtools/common/src/main/resources/templates/basic-rest/scala/build.gradle-template.ftl @@ -20,20 +20,6 @@ repositories { mavenCentral() } -sourceSets { - nativeTest { - compileClasspath += sourceSets.main.output - compileClasspath += sourceSets.test.output - runtimeClasspath += sourceSets.main.output - runtimeClasspath += sourceSets.test.output - } -} - -configurations { - nativeTestImplementation.extendsFrom implementation - nativeTestRuntimeOnly.extendsFrom runtimeOnly -} - dependencies { implementation enforcedPlatform("io.quarkus:quarkus-bom:${quarkusVersion}") implementation 'io.quarkus:quarkus-resteasy' @@ -48,20 +34,3 @@ dependencies { group '${project_groupId}' version '${project_version}' -test { - useJUnitPlatform() -} - -task testNative(type: Test) { - useJUnitPlatform() - description = 'Runs native image tests' - group = 'verification' - - testClassesDirs = sourceSets.nativeTest.output.classesDirs - classpath = sourceSets.nativeTest.runtimeClasspath - shouldRunAfter test -} - -testNative.dependsOn buildNative -check.dependsOn testNative - diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java b/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java index 555277471721d..4aa1735c44d0f 100644 --- a/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/QuarkusPlugin.java @@ -1,11 +1,18 @@ package io.quarkus.gradle; +import java.util.Collections; + import org.gradle.api.GradleException; import org.gradle.api.Plugin; import org.gradle.api.Project; import org.gradle.api.Task; +import org.gradle.api.artifacts.ConfigurationContainer; import org.gradle.api.plugins.BasePlugin; import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.SourceSetOutput; import org.gradle.api.tasks.TaskContainer; import org.gradle.api.tasks.testing.Test; import org.gradle.util.GradleVersion; @@ -17,6 +24,7 @@ import io.quarkus.gradle.tasks.QuarkusListExtensions; import io.quarkus.gradle.tasks.QuarkusNative; import io.quarkus.gradle.tasks.QuarkusTestConfig; +import io.quarkus.gradle.tasks.QuarkusTestNative; /** * @author Ståle Pedersen @@ -52,11 +60,38 @@ private void registerTasks(Project project) { quarkusBuild.dependsOn(classesTask); }); - tasks.create("buildNative", QuarkusNative.class).dependsOn(quarkusBuild); + Task buildNative = tasks.create("buildNative", QuarkusNative.class).dependsOn(quarkusBuild); + + // set up the source set for the testNative + JavaPluginConvention javaPlugin = project.getConvention().findPlugin(JavaPluginConvention.class); + if (javaPlugin != null) { + SourceSetContainer sourceSets = javaPlugin.getSourceSets(); + SourceSet nativeTestSourceSet = sourceSets.create("native-test"); // this name has to be the same as the directory in which the tests reside + SourceSetOutput mainSourceSetOutput = sourceSets.getByName("main").getOutput(); + SourceSetOutput testSourceSetOutput = sourceSets.getByName("test").getOutput(); + nativeTestSourceSet.setCompileClasspath( + nativeTestSourceSet.getCompileClasspath().plus(mainSourceSetOutput).plus(testSourceSetOutput)); + nativeTestSourceSet.setRuntimeClasspath( + nativeTestSourceSet.getRuntimeClasspath().plus(mainSourceSetOutput).plus(testSourceSetOutput)); + + // create a custom configuration to be used for the dependencies of the testNative task + ConfigurationContainer configurations = project.getConfigurations(); + configurations.maybeCreate("nativeTestImplementation").extendsFrom(configurations.findByName("implementation")); + configurations.maybeCreate("nativeTestRuntimeOnly").extendsFrom(configurations.findByName("runtimeOnly")); + + Task testNative = tasks.create("testNative", QuarkusTestNative.class).dependsOn(buildNative); + testNative.setShouldRunAfter(Collections.singletonList(tasks.findByName("test"))); + + tasks.getByName("check").dependsOn(testNative); + } - // Quarkus test configuration task which should be executed before any Quarkus test final QuarkusTestConfig quarkusTestConfig = tasks.create("quarkusTestConfig", QuarkusTestConfig.class); - tasks.withType(Test.class).forEach(t -> t.dependsOn(quarkusTestConfig)); + tasks.withType(Test.class).forEach(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(); + }); } private void verifyGradleVersion() { diff --git a/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusTestNative.java b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusTestNative.java new file mode 100644 index 0000000000000..c043cdfad0c31 --- /dev/null +++ b/devtools/gradle/src/main/java/io/quarkus/gradle/tasks/QuarkusTestNative.java @@ -0,0 +1,21 @@ +package io.quarkus.gradle.tasks; + +import org.gradle.api.plugins.JavaPluginConvention; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.testing.Test; + +public class QuarkusTestNative extends Test { + + public QuarkusTestNative() { + setDescription("Runs native image tests"); + setGroup("verification"); + + JavaPluginConvention javaPlugin = getProject().getConvention().getPlugin(JavaPluginConvention.class); + SourceSetContainer sourceSets = javaPlugin.getSourceSets(); + SourceSet sourceSet = sourceSets.findByName("native-test"); + + setTestClassesDirs(sourceSet.getOutput().getClassesDirs()); + setClasspath(sourceSet.getRuntimeClasspath()); + } +} diff --git a/docs/src/main/asciidoc/gradle-tooling.adoc b/docs/src/main/asciidoc/gradle-tooling.adoc index 889c48fdfe6cd..26bce85c23f9f 100644 --- a/docs/src/main/asciidoc/gradle-tooling.adoc +++ b/docs/src/main/asciidoc/gradle-tooling.adoc @@ -126,25 +126,9 @@ dependencies { == Enable Tests -Quarkus uses Junit5 and to enable it in Gradle we need to add a section to our build file: - -[source,groovy,subs=attributes+] ----- -test { - useJUnitPlatform() - exclude '**/Native*' -} ----- - -Using the Kotlin DSL, add: - -[source,kotlin,subs=attributes+] ----- -tasks.test { - useJUnitPlatform() - exclude("**/Native*") -} ----- +When the Quarkus Gradle plugin is applied to a build, the `test` task is configured to run regular tests while the `testNative` task +is meant to run the native image tests. +The source code for the native image tests should reside in `src/native-test` instead of `src/test` where the source code for regular tests resides. To follow up our Rest example from above, we would also need to add two test dependencies: @@ -182,7 +166,6 @@ database. [source,groovy,subs=attributes+] ---- test { - useJUnitPlatform() systemProperty "quarkus.test.profile", "foo" <1> } ---- @@ -192,7 +175,6 @@ or, if you use the Gradle Kotlin DSL: [source,kotlin,subs=attributes+] ---- tasks.test { - useJUnitPlatform() systemProperty("quarkus.test.profile", "foo") <1> } ---- diff --git a/docs/src/main/asciidoc/kotlin.adoc b/docs/src/main/asciidoc/kotlin.adoc index 1972d14344312..0d30e22b5e9d6 100644 --- a/docs/src/main/asciidoc/kotlin.adoc +++ b/docs/src/main/asciidoc/kotlin.adoc @@ -280,11 +280,6 @@ tasks { } } -tasks.test { - useJUnitPlatform() - exclude("**/Native*") -} - allOpen { // <5> annotation("javax.ws.rs.Path") annotation("javax.enterprise.context.ApplicationScoped") diff --git a/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java b/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java index 156e9fcf5801c..0c9c0a8bf658f 100644 --- a/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java +++ b/test-framework/common/src/main/java/io/quarkus/test/common/PathTestHelper.java @@ -22,19 +22,19 @@ public final class PathTestHelper { "bin" + File.separator + "main"); // gradle TEST_TO_MAIN_DIR_FRAGMENTS.put( - "classes" + File.separator + "java" + File.separator + "nativeTest", + "classes" + File.separator + "java" + File.separator + "native-test", "classes" + File.separator + "java" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( "classes" + File.separator + "java" + File.separator + "test", "classes" + File.separator + "java" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( - "classes" + File.separator + "kotlin" + File.separator + "nativeTest", + "classes" + File.separator + "kotlin" + File.separator + "native-test", "classes" + File.separator + "kotlin" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( "classes" + File.separator + "kotlin" + File.separator + "test", "classes" + File.separator + "kotlin" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( - "classes" + File.separator + "scala" + File.separator + "nativeTest", + "classes" + File.separator + "scala" + File.separator + "native-test", "classes" + File.separator + "scala" + File.separator + "main"); TEST_TO_MAIN_DIR_FRAGMENTS.put( "classes" + File.separator + "scala" + File.separator + "test",