Skip to content

Commit

Permalink
Remove Groovy test code & move everything to Kotlin (#136)
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Schnelle authored Dec 30, 2018
1 parent db25fd0 commit 96a4b9e
Show file tree
Hide file tree
Showing 20 changed files with 402 additions and 490 deletions.

This file was deleted.

This file was deleted.

15 changes: 0 additions & 15 deletions .idea/runConfigurations/Sample__Run_Unit_Tests__IDE_.xml

This file was deleted.

44 changes: 35 additions & 9 deletions android-junit5-tests/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,31 @@ val compileTestGroovy = tasks.getByName("compileTestGroovy") as AbstractCompile
val compileTestKotlin = tasks.getByName("compileTestKotlin") as AbstractCompile
val testClassesTask = tasks.getByName("testClasses")

compileTestGroovy.dependsOn.remove("compileTestJava")
compileTestKotlin.dependsOn.add(compileTestGroovy)
compileTestKotlin.classpath += project.files(compileTestGroovy.destinationDir)
testClassesTask.dependsOn.add(compileTestKotlin)
compileTestKotlin.dependsOn.remove("compileTestJava")
compileTestGroovy.dependsOn.add(compileTestKotlin)
compileTestGroovy.classpath += project.files(compileTestKotlin.destinationDir)

// Add custom dependency configurations
configurations {
create("functionalTest") {
description = "Local dependencies used for compiling & running " +
"tests source code in Gradle functional tests"
}

create("functionalTestAgp32X") {
description = "Local dependencies used for compiling & running " +
"tests source code in Gradle functional tests against AGP 3.2.X"
}

create("functionalTestAgp33X") {
description = "Local dependencies used for compiling & running " +
"tests source code in Gradle functional tests against AGP 3.3.X"
}

create("functionalTestAgp34X") {
description = "Local dependencies used for compiling & running " +
"tests source code in Gradle functional tests against AGP 3.4.X"
}
}

val processTestResources = tasks.getByName("processTestResources") as Copy
Expand Down Expand Up @@ -82,15 +96,24 @@ dependencies {
testImplementation(extra["libs.mockito"] as String)

testRuntimeOnly(extra["libs.junitJupiterEngine"] as String)
testRuntimeOnly(extra["libs.junitVintageEngine"] as String)
testRuntimeOnly(extra["libs.spekEngine"] as String)

// Compilation of local classpath for functional tests
val functionalTest by configurations
functionalTest(kotlin("compiler-embeddable", extra["versions.kotlin"] as String))
functionalTest(extra["libs.junit4"] as String)
functionalTest(extra["plugins.android"] as String)
functionalTest(extra["libs.junitJupiterApi"] as String)
functionalTest(extra["libs.junitJupiterEngine"] as String)

val functionalTestAgp32X by configurations
functionalTestAgp32X(extra["plugins.android.32X"] as String)

val functionalTestAgp33X by configurations
functionalTestAgp33X(extra["plugins.android.33X"] as String)

val functionalTestAgp34X by configurations
functionalTestAgp34X(extra["plugins.android.34X"] as String)
}

// Resource Writers
Expand All @@ -100,10 +123,13 @@ tasks.create("writePluginClasspath", WriteClasspathResource::class) {
resourceFileName = "plugin-classpath.txt"
}

tasks.create("writeFunctionalTestCompileClasspath", WriteClasspathResource::class) {
inputFiles = configurations["functionalTest"]
outputDir = File("$buildDir/resources/test")
resourceFileName = "functional-test-compile-classpath.txt"
// Create a classpath-generating task for all functional test configurations
listOf("functionalTest", "functionalTestAgp32X", "functionalTestAgp33X", "functionalTestAgp34X").forEach { config ->
tasks.create("write${config.capitalize()}CompileClasspath", WriteClasspathResource::class) {
inputFiles = configurations[config]
outputDir = File("$buildDir/resources/test")
resourceFileName = "$config-compile-classpath.txt"
}
}

val testTask = tasks.getByName("test")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,38 +1,36 @@
package de.mannodermaus.gradle.plugins.junit5

import de.mannodermaus.gradle.plugins.junit5.util.TestEnvironment
import de.mannodermaus.gradle.plugins.junit5.util.TestProjectFactory
import de.mannodermaus.gradle.plugins.junit5.util.TestEnvironment2
import de.mannodermaus.gradle.plugins.junit5.util.TestProjectFactory2
import kotlin.io.FilesKt
import org.gradle.api.Project
import org.gradle.api.tasks.testing.Test
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.DisplayName
import org.junit.After
import org.junit.Before

import static org.assertj.core.api.Assertions.assertThat

class DslGroovyTests {

private TestProjectFactory factory
private TestProjectFactory2 factory
private Project testRoot

@BeforeEach
@Before
void beforeEach() {
def environment = new TestEnvironment()
def environment = new TestEnvironment2()

this.factory = new TestProjectFactory(environment)
this.factory = new TestProjectFactory2(environment)
this.testRoot = factory.newRootProject()
}

@AfterEach
@After
void afterEach() {
FilesKt.deleteRecursively(this.testRoot.rootDir)
}

@org.junit.jupiter.api.Test
@DisplayName("dynamic filters methods can be called on existing build types")
@org.junit.Test
void dynamicFiltersMethodsCanBeCalledOnExistingBuildTypes() {
def project = factory.newProject(testRoot)
def project = factory.newProject(testRoot, null)
.asAndroidApplication()
.build()

Expand All @@ -57,10 +55,9 @@ class DslGroovyTests {
assertThat(releaseTask.testFramework.options.excludeTags).containsOnly("other-tag")
}

@org.junit.jupiter.api.Test
@DisplayName("dynamic filters methods can be called on existing product flavors")
@org.junit.Test
void dynamicFiltersMethodsCanBeCalledOnExistingProductFlavors() {
def project = factory.newProject(testRoot)
def project = factory.newProject(testRoot, null)
.asAndroidApplication()
.build()

Expand Down Expand Up @@ -114,10 +111,9 @@ class DslGroovyTests {
assertThat(paidReleaseTask.testFramework.options.excludeTags).containsOnly("other-tag")
}

@org.junit.jupiter.api.Test
@DisplayName("complex example with multiple flavor dimensions & build types")
@org.junit.Test
void complexExampleWithMultipleFlavorDimensionsAndBuildTypes() {
def project = factory.newProject(testRoot)
def project = factory.newProject(testRoot, null)
.asAndroidApplication()
.build()

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 96a4b9e

Please sign in to comment.