From 935b13c8badba8fd7f88cc2ac552c31e18b76765 Mon Sep 17 00:00:00 2001 From: Marcel Schnelle Date: Sun, 8 Apr 2018 15:36:07 +0900 Subject: [PATCH 1/5] Add UnitTestOptions#includeAndroidResources and #returnDefaultValues to DSL --- .../mannodermaus/gradle/plugins/junit5/Dsl.kt | 50 +++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt index 8316a2ec..f845e734 100644 --- a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt +++ b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt @@ -43,6 +43,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * The version of JUnit Platform to use */ var platformVersion: String? = null + fun platformVersion(version: String?) { this.platformVersion = version } @@ -51,6 +52,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * The version of JUnit Jupiter to use */ var jupiterVersion: String? = null + fun jupiterVersion(version: String?) { this.jupiterVersion = version } @@ -59,6 +61,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * The version of JUnit Vintage to use */ var vintageVersion: String? = null + fun vintageVersion(version: String?) { this.vintageVersion = version } @@ -67,6 +70,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * The directory for the test report files */ var reportsDir: File? = null + fun reportsDir(reportsDir: File?) { // Work around for https://discuss.gradle.org/t/bug-in-project-file-on-windows/19917 if (reportsDir is File) { @@ -82,6 +86,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * system property to this value */ var logManager: String? = null + fun logManager(logManager: String?) { this.logManager = logManager } @@ -90,6 +95,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * Whether or not the standard Gradle {@code test} task should be enabled */ var enableStandardTestTask = false + fun enableStandardTestTask(state: Boolean) { this.enableStandardTestTask = state } @@ -98,6 +104,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * Select test execution plan details mode */ var details = Details.NONE + fun details(details: Details) { this.details = details } @@ -482,10 +489,46 @@ class UnitTestOptions { * - environment variables */ var applyDefaultTestOptions = true + fun applyDefaultTestOptions(state: Boolean) { this.applyDefaultTestOptions = state } + /** + * Whether unmocked methods from android.jar should throw exceptions or return default + * values (i.e. zero or null). + * + * Defaults to false, which will throw exceptions on unmocked method invocations + */ + var returnDefaultValues = false + + /** + * Enables unit tests to use Android resources, assets, and manifests. + *

+ * If you enable this setting, the Android Gradle Plugin performs resource, asset, + * and manifest merging before running your unit tests. Your tests can then inspect a file + * called {@code com/android/tools/test_config.properties} on the classpath, which is a Java + * properties file with the following keys: + * + *

+ */ + var includeAndroidResources = false + /** * Applies the provided config closure to all JUnit 5 test tasks, * and any task that'll be added in the future @@ -535,6 +578,7 @@ class InstrumentationTestOptions { * Whether or not to enable support for JUnit 5 instrumentation tests */ var enabled: Boolean = true + fun enabled(state: Boolean) { this.enabled = state } @@ -543,6 +587,7 @@ class InstrumentationTestOptions { * The version of the instrumentation companion library to use */ var version: String? = null + fun version(version: String?) { this.version = version } @@ -562,6 +607,7 @@ class JacocoOptions { * Whether or not to enable Jacoco task integration */ var taskGenerationEnabled = true + fun taskGenerationEnabled(state: Boolean) { this.taskGenerationEnabled = state } @@ -620,6 +666,7 @@ class JacocoOptions { * By default, this will exclude R.class & BuildConfig.class */ var excludedClasses = mutableListOf("**/R.class", "**/R$*.class", "**/BuildConfig.*") + fun excludedClasses(vararg classes: String) = excludedClasses.addAll(classes) /** @@ -627,6 +674,7 @@ class JacocoOptions { * By default, this is an empty list */ var excludedSources = mutableListOf() + fun excludedSources(vararg sources: String) = excludedSources.addAll(sources) class Report { @@ -639,6 +687,7 @@ class JacocoOptions { * Whether or not this report should be generated */ var enabled: Boolean = true + fun enabled(state: Boolean) { this.enabled = state } @@ -649,6 +698,7 @@ class JacocoOptions { * each variant will be assigned a distinct folder if necessary */ var destination: File? = null + fun destination(file: File?) { this.destination = file } From 3004f79012b7ea6f81286844c98644db030797cf Mon Sep 17 00:00:00 2001 From: Marcel Schnelle Date: Sun, 8 Apr 2018 16:30:40 +0900 Subject: [PATCH 2/5] Implement DSL mirror for UnitTestOptions#returnDefaultValues & tests for that --- android-junit5-tests/build.gradle | 9 ++-- .../gradle/plugins/junit5/PluginSpec.kt | 26 +++++++++++ .../mannodermaus/gradle/plugins/junit5/Dsl.kt | 18 ++++++-- .../gradle/plugins/junit5/Plugin.kt | 45 ++++++++++--------- .../gradle/plugins/junit5/tasks/UnitTest.kt | 7 ++- 5 files changed, 77 insertions(+), 28 deletions(-) diff --git a/android-junit5-tests/build.gradle b/android-junit5-tests/build.gradle index 1fad11a3..98483583 100644 --- a/android-junit5-tests/build.gradle +++ b/android-junit5-tests/build.gradle @@ -46,9 +46,12 @@ processTestResources { } } -test.testLogging { - events "passed", "skipped", "failed" - exceptionFormat = "full" +test { + failFast = true + testLogging { + events "passed", "skipped", "failed" + exceptionFormat = "full" + } } junitPlatform { diff --git a/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt b/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt index 6226b30e..9b7bd397 100644 --- a/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt +++ b/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt @@ -455,6 +455,32 @@ class PluginSpec : Spek({ } } + context("unitTests.returnDefaultValues") { + val project by memoized { testProjectBuilder.build() } + + listOf(true, false).forEach { state -> + on("set to $state") { + project.android.testOptions.junitPlatform.unitTests { + returnDefaultValues = state + } + + project.evaluate() + + it("generates a mockable android.jar with the correct suffix") { + val variant = ProjectConfig(project).unitTestVariants.first() + val file = variant.variantData.scope.globalScope.mockableAndroidJarFile + val assertion = assertThat(file.name) + + if (state) { + assertion.contains("default-values") + } else { + assertion.doesNotContain("default-values") + } + } + } + } + } + context("jacoco integration") { beforeEachTest { testProjectBuilder.applyJacocoPlugin() } diff --git a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt index f845e734..663d9611 100644 --- a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt +++ b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt @@ -164,7 +164,7 @@ open class AndroidJUnitPlatformExtension(private val project: Project) { * * @since 1.0.23 */ - val unitTests = UnitTestOptions() + val unitTests = UnitTestOptions(project) /** * Configures unit test options @@ -469,7 +469,7 @@ open class IncludeExcludeContainer { /** * Options for controlling how JUnit 5 Unit Tests should be executed */ -class UnitTestOptions { +class UnitTestOptions(private val project: Project) { operator fun invoke(config: UnitTestOptions.() -> Unit) { this.config() @@ -499,8 +499,13 @@ class UnitTestOptions { * values (i.e. zero or null). * * Defaults to false, which will throw exceptions on unmocked method invocations + * + * @since 1.0.32 */ - var returnDefaultValues = false + var returnDefaultValues: Boolean = false + set(value) { + project.android.testOptions.unitTests.isReturnDefaultValues = value + } /** * Enables unit tests to use Android resources, assets, and manifests. @@ -526,8 +531,13 @@ class UnitTestOptions { * modify the application ID in your build scripts, this package name may not match * the package attribute in the final app manifest. * + * + * @since 1.0.32 */ - var includeAndroidResources = false + var includeAndroidResources: Boolean = false + set(value) { + project.android.testOptions.unitTests.isIncludeAndroidResources = value + } /** * Applies the provided config closure to all JUnit 5 test tasks, diff --git a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Plugin.kt b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Plugin.kt index 37742e56..fa8153a9 100644 --- a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Plugin.kt +++ b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Plugin.kt @@ -40,9 +40,11 @@ class AndroidJUnitPlatformPlugin : Plugin { project.configureExtensions() project.configureDependencies() + project.afterEvaluate { - it.configureTasks() - it.applyConfigurationParameters() + it.configureTestTasks() + it.configureJacocoTasks() + it.applyEvaluatedConfiguration() } } @@ -80,27 +82,30 @@ class AndroidJUnitPlatformPlugin : Plugin { runnerArgs.append(RUNNER_BUILDER_ARG, JUNIT5_RUNNER_BUILDER_CLASS_NAME) } - private fun Project.configureTasks() { - // Add the test task to each of the project's unit test variants, - // and connect a Code Coverage report to it if Jacoco is enabled. - val testVariants = projectConfig.unitTestVariants - val isJacocoApplied = projectConfig.jacocoPluginApplied - - testVariants.all { variant -> + private fun Project.configureTestTasks() { + // Add the test task to each of the project's unit test variants + projectConfig.unitTestVariants.all { variant -> val directoryProviders = collectDirectoryProviders(variant) + AndroidJUnit5UnitTest.create(this, variant, directoryProviders) + } + } + + /* After evaluate */ - // Create JUnit 5 test task - val testTask = AndroidJUnit5UnitTest.create(this, variant, directoryProviders) + private fun Project.configureJacocoTasks() { + // Connect a Code Coverage report to it if Jacoco is enabled. + val isJacocoApplied = projectConfig.jacocoPluginApplied + val jacocoOptions = this.android.testOptions.junitPlatform.jacocoOptions - if (isJacocoApplied) { - val jacocoOptions = this.android.testOptions.junitPlatform.jacocoOptions + if (isJacocoApplied && jacocoOptions.taskGenerationEnabled) { + projectConfig.unitTestVariants.all { variant -> + val directoryProviders = collectDirectoryProviders(variant) + val testTask = AndroidJUnit5UnitTest.find(project, variant) - if (jacocoOptions.taskGenerationEnabled) { - // Create a Jacoco friend task - val enabledVariants = jacocoOptions.onlyGenerateTasksForVariants - if (enabledVariants.isEmpty() || enabledVariants.contains(variant.name)) { - AndroidJUnit5JacocoReport.create(this, testTask, directoryProviders) - } + // Create a Jacoco friend task + val enabledVariants = jacocoOptions.onlyGenerateTasksForVariants + if (enabledVariants.isEmpty() || enabledVariants.contains(variant.name)) { + AndroidJUnit5JacocoReport.create(this, testTask, directoryProviders) } } } @@ -121,7 +126,7 @@ class AndroidJUnitPlatformPlugin : Plugin { return providers } - private fun Project.applyConfigurationParameters() { + private fun Project.applyEvaluatedConfiguration() { // Verify that the JUnit 5 RunnerBuilder wasn't overwritten by user code, // and if so, throw an exception val actualRunnerBuilder = android.defaultConfig.testInstrumentationRunnerArguments[RUNNER_BUILDER_ARG]!! diff --git a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt index 4f865432..30235034 100644 --- a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt +++ b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt @@ -16,7 +16,6 @@ import de.mannodermaus.gradle.plugins.junit5.variantData import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.Task -import org.gradle.api.file.FileCollection import org.gradle.api.internal.file.IdentityFileResolver import org.gradle.api.plugins.JavaBasePlugin import org.gradle.api.tasks.InputFiles @@ -39,6 +38,12 @@ private const val VERIFICATION_GROUP = JavaBasePlugin.VERIFICATION_GROUP open class AndroidJUnit5UnitTest : JavaExec(), JUnit5UnitTest { companion object { + fun find(project: Project, variant: BaseVariant): AndroidJUnit5UnitTest { + return project.tasks.getByName( + variant.variantData.scope.getTaskName(TASK_NAME_DEFAULT)) + as AndroidJUnit5UnitTest + } + fun create( project: Project, variant: BaseVariant, From 82d220e3db4a6b0a99e73922ffbf39849098e1bd Mon Sep 17 00:00:00 2001 From: Marcel Schnelle Date: Sun, 8 Apr 2018 16:39:36 +0900 Subject: [PATCH 3/5] Implement DSL mirror for UnitTestOptions#includeAndroidResources --- .../gradle/plugins/junit5/PluginSpec.kt | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt b/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt index 9b7bd397..8c29be8c 100644 --- a/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt +++ b/android-junit5-tests/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/PluginSpec.kt @@ -466,6 +466,11 @@ class PluginSpec : Spek({ project.evaluate() + it("configures the AGP setting correctly") { + assertThat(project.android.testOptions.unitTests.isReturnDefaultValues) + .isEqualTo(state) + } + it("generates a mockable android.jar with the correct suffix") { val variant = ProjectConfig(project).unitTestVariants.first() val file = variant.variantData.scope.globalScope.mockableAndroidJarFile @@ -481,6 +486,25 @@ class PluginSpec : Spek({ } } + context("unitTests.includeAndroidResources") { + val project by memoized { testProjectBuilder.build() } + + listOf(true, false).forEach { state -> + on("set to $state") { + project.android.testOptions.junitPlatform.unitTests { + includeAndroidResources = state + } + + project.evaluate() + + it("configures the AGP setting correctly") { + assertThat(project.android.testOptions.unitTests.isIncludeAndroidResources) + .isEqualTo(state) + } + } + } + } + context("jacoco integration") { beforeEachTest { testProjectBuilder.applyJacocoPlugin() } From cbd5ec4a634cc156306993819cfcc53d39d39c41 Mon Sep 17 00:00:00 2001 From: Marcel Schnelle Date: Sun, 8 Apr 2018 16:57:35 +0900 Subject: [PATCH 4/5] Draft functional test for includeAndroidResources --- .../plugins/junit5/FunctionalSpec.groovy | 487 ++++++++++-------- .../mannodermaus/gradle/plugins/junit5/Dsl.kt | 6 +- 2 files changed, 271 insertions(+), 222 deletions(-) diff --git a/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy b/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy index 51aec9fc..8ff5ceb0 100644 --- a/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy +++ b/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy @@ -63,225 +63,249 @@ class FunctionalSpec extends Specification { * =============================================================================================== */ - def "Executes Java tests in default source set"() { - given: - androidPlugin() - junit5Plugin() - javaFile() - javaTest() - - when: - BuildResult result = runGradle() - .withArguments("build") - .build() - - then: - result.task(":build").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS - - // 1 per build type (Debug & Release) - StringUtils.countMatches(result.output, "1 tests successful") == 2 - } - - def "Executes Kotlin tests in default source set"() { - given: - androidPlugin() - kotlinPlugin() - junit5Plugin() - javaFile() - kotlinTest() - - when: - BuildResult result = runGradle() - .withArguments("build") - .build() - - then: - result.task(":build").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS - - // 1 per build type (Debug & Release) - StringUtils.countMatches(result.output, "1 tests successful") == 2 - } - - def "Executes Java tests in build-type-specific source set"() { - given: - androidPlugin() - junit5Plugin() - javaFile() - javaTest() - javaTest(null, "debug") - - when: - BuildResult result = runGradle() - .withArguments("junitPlatformTestDebug") - .build() - - then: - result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS - result.output.contains("2 tests successful") - result.output.contains("JavaDebugAdderTest") - result.output.contains("JavaAdderTest") - - when: - result = runGradle() - .withArguments("junitPlatformTestRelease") - .build() - - then: - result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS - result.output.contains("1 tests successful") - result.output.contains("JavaAdderTest") - } - - def "Executes Kotlin tests in build-type-specific source set"() { - given: - androidPlugin() - kotlinPlugin() - junit5Plugin() - javaFile() - kotlinTest() - kotlinTest(null, "debug") - - when: - BuildResult result = runGradle() - .withArguments("junitPlatformTestDebug") - .build() - - then: - result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS - result.output.contains("2 tests successful") - result.output.contains("KotlinDebugAdderTest") - result.output.contains("KotlinAdderTest") - - when: - result = runGradle() - .withArguments("junitPlatformTestRelease") - .build() - - then: - result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS - result.output.contains("1 tests successful") - result.output.contains("KotlinAdderTest") - } - - def "Executes Java tests in flavor-specific source set"() { - given: - androidPlugin(flavorNames: ["free"]) - junit5Plugin() - javaFile() - javaTest() - javaTest("free", null) - - when: - BuildResult result = runGradle() - .withArguments("build") - .build() - - then: - result.task(":build").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS - - // 1 per build type (Debug & Release) - StringUtils.countMatches(result.output, "2 tests successful") == 2 - } - - def "Executes Kotlin tests in flavor-specific source set"() { - given: - androidPlugin(flavorNames: ["free"]) - kotlinPlugin() - junit5Plugin() - javaFile() - kotlinTest() - kotlinTest("free", null) - - when: - BuildResult result = runGradle() - .withArguments("build") - .build() - - then: - result.task(":build").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS - result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS - - // 1 per build type (Debug & Release) - StringUtils.countMatches(result.output, "2 tests successful") == 2 - } - - def "Executes Java tests in build-type-and-flavor-specific source set"() { - given: - androidPlugin(flavorNames: ["free"]) - junit5Plugin() - javaFile() - javaTest() - javaTest(null, "debug") - javaTest("free", "debug") - javaTest(null, "release") - GradleRunner runner = runGradle() - - when: - BuildResult result = runner - .withArguments("junitPlatformTestFreeDebug") - .build() - - then: - result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS - result.output.contains("3 tests successful") - result.output.contains("JavaFreeDebugAdderTest") - result.output.contains("JavaDebugAdderTest") - result.output.contains("JavaAdderTest") - - when: - result = runner - .withArguments("junitPlatformTestFreeRelease") - .build() - - then: - result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS - result.output.contains("2 tests successful") - result.output.contains("JavaReleaseAdderTest") - result.output.contains("JavaAdderTest") - } - - def "Executes Kotlin tests in build-type-and-flavor-specific source set"() { - given: - androidPlugin(flavorNames: ["free"]) - kotlinPlugin() - junit5Plugin() - javaFile() - kotlinTest() - kotlinTest("free", "debug") - kotlinTest(null, "debug") - kotlinTest(null, "release") - GradleRunner runner = runGradle() - - when: - BuildResult result = runner - .withArguments("junitPlatformTestFreeDebug") - .build() - - then: - result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS - result.output.contains("3 tests successful") - result.output.contains("KotlinFreeDebugAdderTest") - result.output.contains("KotlinDebugAdderTest") - result.output.contains("KotlinAdderTest") - - when: - result = runner - .withArguments("junitPlatformTestFreeRelease") - .build() - - then: - result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS - result.output.contains("2 tests successful") - result.output.contains("KotlinReleaseAdderTest") - result.output.contains("KotlinAdderTest") - } +// def "Executes Java tests in default source set"() { +// given: +// androidPlugin() +// junit5Plugin() +// javaFile() +// javaTest() +// +// when: +// BuildResult result = runGradle() +// .withArguments("build") +// .build() +// +// then: +// result.task(":build").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS +// +// // 1 per build type (Debug & Release) +// StringUtils.countMatches(result.output, "1 tests successful") == 2 +// } +// +// def "Executes Kotlin tests in default source set"() { +// given: +// androidPlugin() +// kotlinPlugin() +// junit5Plugin() +// javaFile() +// kotlinTest() +// +// when: +// BuildResult result = runGradle() +// .withArguments("build") +// .build() +// +// then: +// result.task(":build").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS +// +// // 1 per build type (Debug & Release) +// StringUtils.countMatches(result.output, "1 tests successful") == 2 +// } +// +// def "Executes Java tests in build-type-specific source set"() { +// given: +// androidPlugin() +// junit5Plugin() +// javaFile() +// javaTest() +// javaTest(null, "debug") +// +// when: +// BuildResult result = runGradle() +// .withArguments("junitPlatformTestDebug") +// .build() +// +// then: +// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS +// result.output.contains("2 tests successful") +// result.output.contains("JavaDebugAdderTest") +// result.output.contains("JavaAdderTest") +// +// when: +// result = runGradle() +// .withArguments("junitPlatformTestRelease") +// .build() +// +// then: +// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS +// result.output.contains("1 tests successful") +// result.output.contains("JavaAdderTest") +// } +// +// def "Executes Kotlin tests in build-type-specific source set"() { +// given: +// androidPlugin() +// kotlinPlugin() +// junit5Plugin() +// javaFile() +// kotlinTest() +// kotlinTest(null, "debug") +// +// when: +// BuildResult result = runGradle() +// .withArguments("junitPlatformTestDebug") +// .build() +// +// then: +// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS +// result.output.contains("2 tests successful") +// result.output.contains("KotlinDebugAdderTest") +// result.output.contains("KotlinAdderTest") +// +// when: +// result = runGradle() +// .withArguments("junitPlatformTestRelease") +// .build() +// +// then: +// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS +// result.output.contains("1 tests successful") +// result.output.contains("KotlinAdderTest") +// } +// +// def "Executes Java tests in flavor-specific source set"() { +// given: +// androidPlugin(flavorNames: ["free"]) +// junit5Plugin() +// javaFile() +// javaTest() +// javaTest("free", null) +// +// when: +// BuildResult result = runGradle() +// .withArguments("build") +// .build() +// +// then: +// result.task(":build").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS +// +// // 1 per build type (Debug & Release) +// StringUtils.countMatches(result.output, "2 tests successful") == 2 +// } +// +// def "Executes Kotlin tests in flavor-specific source set"() { +// given: +// androidPlugin(flavorNames: ["free"]) +// kotlinPlugin() +// junit5Plugin() +// javaFile() +// kotlinTest() +// kotlinTest("free", null) +// +// when: +// BuildResult result = runGradle() +// .withArguments("build") +// .build() +// +// then: +// result.task(":build").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS +// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS +// +// // 1 per build type (Debug & Release) +// StringUtils.countMatches(result.output, "2 tests successful") == 2 +// } +// +// def "Executes Java tests in build-type-and-flavor-specific source set"() { +// given: +// androidPlugin(flavorNames: ["free"]) +// junit5Plugin() +// javaFile() +// javaTest() +// javaTest(null, "debug") +// javaTest("free", "debug") +// javaTest(null, "release") +// GradleRunner runner = runGradle() +// +// when: +// BuildResult result = runner +// .withArguments("junitPlatformTestFreeDebug") +// .build() +// +// then: +// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS +// result.output.contains("3 tests successful") +// result.output.contains("JavaFreeDebugAdderTest") +// result.output.contains("JavaDebugAdderTest") +// result.output.contains("JavaAdderTest") +// +// when: +// result = runner +// .withArguments("junitPlatformTestFreeRelease") +// .build() +// +// then: +// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS +// result.output.contains("2 tests successful") +// result.output.contains("JavaReleaseAdderTest") +// result.output.contains("JavaAdderTest") +// } +// +// def "Executes Kotlin tests in build-type-and-flavor-specific source set"() { +// given: +// androidPlugin(flavorNames: ["free"]) +// kotlinPlugin() +// junit5Plugin() +// javaFile() +// kotlinTest() +// kotlinTest("free", "debug") +// kotlinTest(null, "debug") +// kotlinTest(null, "release") +// GradleRunner runner = runGradle() +// +// when: +// BuildResult result = runner +// .withArguments("junitPlatformTestFreeDebug") +// .build() +// +// then: +// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS +// result.output.contains("3 tests successful") +// result.output.contains("KotlinFreeDebugAdderTest") +// result.output.contains("KotlinDebugAdderTest") +// result.output.contains("KotlinAdderTest") +// +// when: +// result = runner +// .withArguments("junitPlatformTestFreeRelease") +// .build() +// +// then: +// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS +// result.output.contains("2 tests successful") +// result.output.contains("KotlinReleaseAdderTest") +// result.output.contains("KotlinAdderTest") +// } + + + + def "Includes Android resources successfully"() { + given: + androidPlugin() + junit5Plugin(""" + unitTests { + includeAndroidResources = true + } + """) + androidTest() + GradleRunner runner = runGradle() + + when: + BuildResult result = runner + .withArguments("junitPlatformTestDebug") + .build() + + then: + result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS + result.output.contains("1 tests successful") + result.output.contains("AndroidJavaAdderTest") + } /* * =============================================================================================== @@ -357,13 +381,14 @@ class FunctionalSpec extends Specification { """ } - protected final def junit5Plugin() { + protected final def junit5Plugin(String extraConfig = "") { buildFile << """ apply plugin: "de.mannodermaus.android-junit5" android.testOptions { junitPlatform { details "flat" + $extraConfig } } @@ -423,6 +448,28 @@ class FunctionalSpec extends Specification { filePath.withWriter { it.write(content.replace("__NAME__", testName)) } } + protected final def androidTest(String flavorName = null, String buildType = null) { + this.test(language: FileLanguage.Java, + flavorName: flavorName, + buildType: buildType, + content: """ + package de.mannodermaus.app; + + import static org.junit.jupiter.api.Assertions.assertEquals; + + import org.junit.jupiter.api.Test; + import android.content.Intent; + + class Android__NAME__ { + @Test + void test() { + Intent intent = new Intent(); + assertEquals(null, intent.getAction()); + } + } + """) + } + protected final def javaTest(String flavorName = null, String buildType = null) { this.test(language: FileLanguage.Java, flavorName: flavorName, diff --git a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt index 663d9611..23a4874d 100644 --- a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt +++ b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/Dsl.kt @@ -502,7 +502,8 @@ class UnitTestOptions(private val project: Project) { * * @since 1.0.32 */ - var returnDefaultValues: Boolean = false + var returnDefaultValues: Boolean + get() = project.android.testOptions.unitTests.isReturnDefaultValues set(value) { project.android.testOptions.unitTests.isReturnDefaultValues = value } @@ -534,7 +535,8 @@ class UnitTestOptions(private val project: Project) { * * @since 1.0.32 */ - var includeAndroidResources: Boolean = false + var includeAndroidResources: Boolean + get() = project.android.testOptions.unitTests.isIncludeAndroidResources set(value) { project.android.testOptions.unitTests.isIncludeAndroidResources = value } From a891cc9c973214d3d3ff796686354779a5fef33c Mon Sep 17 00:00:00 2001 From: Marcel Schnelle Date: Sun, 8 Apr 2018 17:18:55 +0900 Subject: [PATCH 5/5] Add functional tests for includeAndroidResources & returnDefaultValues --- .../plugins/junit5/FunctionalSpec.groovy | 552 +++++++++--------- .../gradle/plugins/junit5/tasks/UnitTest.kt | 12 +- 2 files changed, 302 insertions(+), 262 deletions(-) diff --git a/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy b/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy index 8ff5ceb0..8968463a 100644 --- a/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy +++ b/android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/FunctionalSpec.groovy @@ -63,249 +63,301 @@ class FunctionalSpec extends Specification { * =============================================================================================== */ -// def "Executes Java tests in default source set"() { -// given: -// androidPlugin() -// junit5Plugin() -// javaFile() -// javaTest() -// -// when: -// BuildResult result = runGradle() -// .withArguments("build") -// .build() -// -// then: -// result.task(":build").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS -// -// // 1 per build type (Debug & Release) -// StringUtils.countMatches(result.output, "1 tests successful") == 2 -// } -// -// def "Executes Kotlin tests in default source set"() { -// given: -// androidPlugin() -// kotlinPlugin() -// junit5Plugin() -// javaFile() -// kotlinTest() -// -// when: -// BuildResult result = runGradle() -// .withArguments("build") -// .build() -// -// then: -// result.task(":build").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS -// -// // 1 per build type (Debug & Release) -// StringUtils.countMatches(result.output, "1 tests successful") == 2 -// } -// -// def "Executes Java tests in build-type-specific source set"() { -// given: -// androidPlugin() -// junit5Plugin() -// javaFile() -// javaTest() -// javaTest(null, "debug") -// -// when: -// BuildResult result = runGradle() -// .withArguments("junitPlatformTestDebug") -// .build() -// -// then: -// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS -// result.output.contains("2 tests successful") -// result.output.contains("JavaDebugAdderTest") -// result.output.contains("JavaAdderTest") -// -// when: -// result = runGradle() -// .withArguments("junitPlatformTestRelease") -// .build() -// -// then: -// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS -// result.output.contains("1 tests successful") -// result.output.contains("JavaAdderTest") -// } -// -// def "Executes Kotlin tests in build-type-specific source set"() { -// given: -// androidPlugin() -// kotlinPlugin() -// junit5Plugin() -// javaFile() -// kotlinTest() -// kotlinTest(null, "debug") -// -// when: -// BuildResult result = runGradle() -// .withArguments("junitPlatformTestDebug") -// .build() -// -// then: -// result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS -// result.output.contains("2 tests successful") -// result.output.contains("KotlinDebugAdderTest") -// result.output.contains("KotlinAdderTest") -// -// when: -// result = runGradle() -// .withArguments("junitPlatformTestRelease") -// .build() -// -// then: -// result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS -// result.output.contains("1 tests successful") -// result.output.contains("KotlinAdderTest") -// } -// -// def "Executes Java tests in flavor-specific source set"() { -// given: -// androidPlugin(flavorNames: ["free"]) -// junit5Plugin() -// javaFile() -// javaTest() -// javaTest("free", null) -// -// when: -// BuildResult result = runGradle() -// .withArguments("build") -// .build() -// -// then: -// result.task(":build").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS -// -// // 1 per build type (Debug & Release) -// StringUtils.countMatches(result.output, "2 tests successful") == 2 -// } -// -// def "Executes Kotlin tests in flavor-specific source set"() { -// given: -// androidPlugin(flavorNames: ["free"]) -// kotlinPlugin() -// junit5Plugin() -// javaFile() -// kotlinTest() -// kotlinTest("free", null) -// -// when: -// BuildResult result = runGradle() -// .withArguments("build") -// .build() -// -// then: -// result.task(":build").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS -// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS -// -// // 1 per build type (Debug & Release) -// StringUtils.countMatches(result.output, "2 tests successful") == 2 -// } -// -// def "Executes Java tests in build-type-and-flavor-specific source set"() { -// given: -// androidPlugin(flavorNames: ["free"]) -// junit5Plugin() -// javaFile() -// javaTest() -// javaTest(null, "debug") -// javaTest("free", "debug") -// javaTest(null, "release") -// GradleRunner runner = runGradle() -// -// when: -// BuildResult result = runner -// .withArguments("junitPlatformTestFreeDebug") -// .build() -// -// then: -// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS -// result.output.contains("3 tests successful") -// result.output.contains("JavaFreeDebugAdderTest") -// result.output.contains("JavaDebugAdderTest") -// result.output.contains("JavaAdderTest") -// -// when: -// result = runner -// .withArguments("junitPlatformTestFreeRelease") -// .build() -// -// then: -// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS -// result.output.contains("2 tests successful") -// result.output.contains("JavaReleaseAdderTest") -// result.output.contains("JavaAdderTest") -// } -// -// def "Executes Kotlin tests in build-type-and-flavor-specific source set"() { -// given: -// androidPlugin(flavorNames: ["free"]) -// kotlinPlugin() -// junit5Plugin() -// javaFile() -// kotlinTest() -// kotlinTest("free", "debug") -// kotlinTest(null, "debug") -// kotlinTest(null, "release") -// GradleRunner runner = runGradle() -// -// when: -// BuildResult result = runner -// .withArguments("junitPlatformTestFreeDebug") -// .build() -// -// then: -// result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS -// result.output.contains("3 tests successful") -// result.output.contains("KotlinFreeDebugAdderTest") -// result.output.contains("KotlinDebugAdderTest") -// result.output.contains("KotlinAdderTest") -// -// when: -// result = runner -// .withArguments("junitPlatformTestFreeRelease") -// .build() -// -// then: -// result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS -// result.output.contains("2 tests successful") -// result.output.contains("KotlinReleaseAdderTest") -// result.output.contains("KotlinAdderTest") -// } - - - - def "Includes Android resources successfully"() { - given: - androidPlugin() - junit5Plugin(""" + def "Executes Java tests in default source set"() { + given: + androidPlugin() + junit5Plugin() + javaFile() + javaTest() + + when: + BuildResult result = runGradle() + .withArguments("build") + .build() + + then: + result.task(":build").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS + + // 1 per build type (Debug & Release) + StringUtils.countMatches(result.output, "1 tests successful") == 2 + } + + def "Executes Kotlin tests in default source set"() { + given: + androidPlugin() + kotlinPlugin() + junit5Plugin() + javaFile() + kotlinTest() + + when: + BuildResult result = runGradle() + .withArguments("build") + .build() + + then: + result.task(":build").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS + + // 1 per build type (Debug & Release) + StringUtils.countMatches(result.output, "1 tests successful") == 2 + } + + def "Executes Java tests in build-type-specific source set"() { + given: + androidPlugin() + junit5Plugin() + javaFile() + javaTest() + javaTest(null, "debug") + + when: + BuildResult result = runGradle() + .withArguments("junitPlatformTestDebug") + .build() + + then: + result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS + result.output.contains("2 tests successful") + result.output.contains("JavaDebugAdderTest") + result.output.contains("JavaAdderTest") + + when: + result = runGradle() + .withArguments("junitPlatformTestRelease") + .build() + + then: + result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS + result.output.contains("1 tests successful") + result.output.contains("JavaAdderTest") + } + + def "Executes Kotlin tests in build-type-specific source set"() { + given: + androidPlugin() + kotlinPlugin() + junit5Plugin() + javaFile() + kotlinTest() + kotlinTest(null, "debug") + + when: + BuildResult result = runGradle() + .withArguments("junitPlatformTestDebug") + .build() + + then: + result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS + result.output.contains("2 tests successful") + result.output.contains("KotlinDebugAdderTest") + result.output.contains("KotlinAdderTest") + + when: + result = runGradle() + .withArguments("junitPlatformTestRelease") + .build() + + then: + result.task(":junitPlatformTestRelease").outcome == TaskOutcome.SUCCESS + result.output.contains("1 tests successful") + result.output.contains("KotlinAdderTest") + } + + def "Executes Java tests in flavor-specific source set"() { + given: + androidPlugin(flavorNames: ["free"]) + junit5Plugin() + javaFile() + javaTest() + javaTest("free", null) + + when: + BuildResult result = runGradle() + .withArguments("build") + .build() + + then: + result.task(":build").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS + + // 1 per build type (Debug & Release) + StringUtils.countMatches(result.output, "2 tests successful") == 2 + } + + def "Executes Kotlin tests in flavor-specific source set"() { + given: + androidPlugin(flavorNames: ["free"]) + kotlinPlugin() + junit5Plugin() + javaFile() + kotlinTest() + kotlinTest("free", null) + + when: + BuildResult result = runGradle() + .withArguments("build") + .build() + + then: + result.task(":build").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS + result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS + + // 1 per build type (Debug & Release) + StringUtils.countMatches(result.output, "2 tests successful") == 2 + } + + def "Executes Java tests in build-type-and-flavor-specific source set"() { + given: + androidPlugin(flavorNames: ["free"]) + junit5Plugin() + javaFile() + javaTest() + javaTest(null, "debug") + javaTest("free", "debug") + javaTest(null, "release") + GradleRunner runner = runGradle() + + when: + BuildResult result = runner + .withArguments("junitPlatformTestFreeDebug") + .build() + + then: + result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS + result.output.contains("3 tests successful") + result.output.contains("JavaFreeDebugAdderTest") + result.output.contains("JavaDebugAdderTest") + result.output.contains("JavaAdderTest") + + when: + result = runner + .withArguments("junitPlatformTestFreeRelease") + .build() + + then: + result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS + result.output.contains("2 tests successful") + result.output.contains("JavaReleaseAdderTest") + result.output.contains("JavaAdderTest") + } + + def "Executes Kotlin tests in build-type-and-flavor-specific source set"() { + given: + androidPlugin(flavorNames: ["free"]) + kotlinPlugin() + junit5Plugin() + javaFile() + kotlinTest() + kotlinTest("free", "debug") + kotlinTest(null, "debug") + kotlinTest(null, "release") + GradleRunner runner = runGradle() + + when: + BuildResult result = runner + .withArguments("junitPlatformTestFreeDebug") + .build() + + then: + result.task(":junitPlatformTestFreeDebug").outcome == TaskOutcome.SUCCESS + result.output.contains("3 tests successful") + result.output.contains("KotlinFreeDebugAdderTest") + result.output.contains("KotlinDebugAdderTest") + result.output.contains("KotlinAdderTest") + + when: + result = runner + .withArguments("junitPlatformTestFreeRelease") + .build() + + then: + result.task(":junitPlatformTestFreeRelease").outcome == TaskOutcome.SUCCESS + result.output.contains("2 tests successful") + result.output.contains("KotlinReleaseAdderTest") + result.output.contains("KotlinAdderTest") + } + + def "Returns default values successfully"() { + given: + androidPlugin() + junit5Plugin(""" + unitTests { + returnDefaultValues = true + } + """) + test(language: FileLanguage.Java, + content: """ + package de.mannodermaus.app; + + import static org.junit.jupiter.api.Assertions.assertNull; + + import org.junit.jupiter.api.Test; + import android.content.Intent; + + class AndroidTest { + @Test + void test() { + Intent intent = new Intent(); + assertNull(intent.getAction()); + } + } + """) + GradleRunner runner = runGradle() + + when: + BuildResult result = runner + .withArguments("junitPlatformTestDebug") + .build() + + then: + result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS + result.output.contains("1 tests successful") + result.output.contains("AndroidTest") + } + + def "Includes Android resources successfully"() { + given: + androidPlugin() + junit5Plugin(""" unitTests { includeAndroidResources = true } """) - androidTest() - GradleRunner runner = runGradle() - - when: - BuildResult result = runner - .withArguments("junitPlatformTestDebug") - .build() - - then: - result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS - result.output.contains("1 tests successful") - result.output.contains("AndroidJavaAdderTest") - } + test(language: FileLanguage.Java, + content: """ + package de.mannodermaus.app; + + import static org.junit.jupiter.api.Assertions.assertNotNull; + + import org.junit.jupiter.api.Test; + import java.io.InputStream; + + class AndroidTest { + @Test + void test() { + InputStream is = getClass().getResourceAsStream("/com/android/tools/test_config.properties"); + assertNotNull(is); + } + } + """) + GradleRunner runner = runGradle() + + when: + BuildResult result = runner + .withArguments("junitPlatformTestDebug") + .build() + + then: + result.task(":junitPlatformTestDebug").outcome == TaskOutcome.SUCCESS + result.output.contains("1 tests successful") + result.output.contains("AndroidTest") + } /* * =============================================================================================== @@ -448,28 +500,6 @@ class FunctionalSpec extends Specification { filePath.withWriter { it.write(content.replace("__NAME__", testName)) } } - protected final def androidTest(String flavorName = null, String buildType = null) { - this.test(language: FileLanguage.Java, - flavorName: flavorName, - buildType: buildType, - content: """ - package de.mannodermaus.app; - - import static org.junit.jupiter.api.Assertions.assertEquals; - - import org.junit.jupiter.api.Test; - import android.content.Intent; - - class Android__NAME__ { - @Test - void test() { - Intent intent = new Intent(); - assertEquals(null, intent.getAction()); - } - } - """) - } - protected final def javaTest(String flavorName = null, String buildType = null) { this.test(language: FileLanguage.Java, flavorName: flavorName, diff --git a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt index 30235034..d5ebf847 100644 --- a/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt +++ b/android-junit5/src/main/kotlin/de/mannodermaus/gradle/plugins/junit5/tasks/UnitTest.kt @@ -16,8 +16,10 @@ import de.mannodermaus.gradle.plugins.junit5.variantData import org.gradle.api.DefaultTask import org.gradle.api.Project import org.gradle.api.Task +import org.gradle.api.file.FileCollection import org.gradle.api.internal.file.IdentityFileResolver import org.gradle.api.plugins.JavaBasePlugin +import org.gradle.api.tasks.Input import org.gradle.api.tasks.InputFiles import org.gradle.api.tasks.JavaExec import org.gradle.api.tasks.Optional @@ -65,6 +67,12 @@ open class AndroidJUnit5UnitTest : JavaExec(), JUnit5UnitTest { @Optional var assetsCollection: Set? = null + @Input + var sdkPlatformDirPath: String? = null + + @InputFiles + var mergedManifest: FileCollection? = null + override val isRunAllTask = false @Suppress("LeakingThis") @@ -137,7 +145,7 @@ open class AndroidJUnit5UnitTest : JavaExec(), JUnit5UnitTest { defaultJUnit5Task.dependsOn(task) // Apply additional user configuration - project.android.testOptions.junitPlatform.unitTests.applyConfiguration(task) + junit5.unitTests.applyConfiguration(task) } /* Private */ @@ -190,6 +198,8 @@ open class AndroidJUnit5UnitTest : JavaExec(), JUnit5UnitTest { val variantUnitTestTask = this.getDefaultJUnit4Task() task.resCollection = variantUnitTestTask.resCollection?.files task.assetsCollection = variantUnitTestTask.safeAssetsCollection + task.sdkPlatformDirPath = variantUnitTestTask.sdkPlatformDirPath + task.mergedManifest = variantUnitTestTask.mergedManifest variantUnitTestTask.enabled = junit5.enableStandardTestTask variantUnitTestTask.dependsOn(task)