Skip to content

Commit

Permalink
Added some info logging & unified 2.x & 3.x test cases even further
Browse files Browse the repository at this point in the history
  • Loading branch information
Marcel Schnelle committed Jun 4, 2017
1 parent adea3d6 commit 8a5ae7c
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ class AndroidJUnitPlatformPlugin extends JUnitPlatformPlugin {
String nameSuffix = map.getOrDefault("nameSuffix", "")
def dependentTasks = map.dependentTasks

project.logger.info("$LOG_TAG Creating JUnit 5 Task for variant '$nameSuffix'...")
project.logger.info("$LOG_TAG Test Root Dirs: $testRootDirs")
project.logger.info("$LOG_TAG Classpath: $classpath.asPath")

project.task(
TASK_NAME + nameSuffix,
type: JavaExec,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package de.mannodermaus.gradle.anj5

import org.gradle.api.Project
import org.gradle.api.internal.plugins.PluginApplicationException
import org.gradle.internal.resolve.ModuleVersionNotFoundException
import org.gradle.testfixtures.ProjectBuilder
import spock.lang.Specification

Expand Down Expand Up @@ -176,10 +177,10 @@ abstract class AndroidJUnitPlatformSpec extends Specification {
p.tasks.getByName("junitPlatformTestRelease")].forEach { task ->
def classpath = task.classpath.collect { it.absolutePath }

// println "---- $task.name"
// classpath.each {
// println " > $it"
// }
println "---- $task.name"
classpath.each {
println " > $it"
}

// Source set's outputs
assert classpath.find { it.contains("test/build/intermediates/classes/") } != null
Expand Down Expand Up @@ -284,4 +285,61 @@ abstract class AndroidJUnitPlatformSpec extends Specification {
// (Project.logging listeners don't seem to work)
assert true == true
}
def "custom junit jupiter version"() {
when:
def nonExistentVersion = "0.0.0"
Project p = ProjectBuilder.builder().withParent(testRoot).build()
p.file(".").mkdir()
p.file("src/main").mkdirs()
p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) }
p.apply plugin: 'com.android.application'
p.apply plugin: 'de.mannodermaus.android-junit5'
p.android {
compileSdkVersion COMPILE_SDK
buildToolsVersion BUILD_TOOLS
defaultConfig {
applicationId APPLICATION_ID
minSdkVersion MIN_SDK
targetSdkVersion TARGET_SDK
versionCode VERSION_CODE
versionName VERSION_NAME
}
}
p.junitPlatform {
// Some arbitrary non-existent version
jupiterVersion nonExistentVersion
}
p.repositories {
jcenter()
}
p.dependencies {
// "testCompile" or "testApi"
invokeMethod(testCompileDependency(), junitJupiter())
}
then:
// AGP 2.x throws a ModuleVersionNotFoundException here
try {
p.evaluate()
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")
} catch (Throwable expected) {
while (expected != null) {
if (expected instanceof ModuleVersionNotFoundException) {
assert expected.message.contains("Could not find org.junit.jupiter")
assert expected.message.contains("$nonExistentVersion")
break
}
expected = expected.cause
}
if (expected == null) {
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,61 +19,4 @@ class AndroidJUnitPlatformAgp2xSpec extends AndroidJUnitPlatformSpec {
protected String testRuntimeDependency() {
return "testApk"
}

def "custom junit jupiter version"() {
when:
def nonExistentVersion = "0.0.0"

Project p = ProjectBuilder.builder().withParent(testRoot).build()
p.file(".").mkdir()
p.file("src/main").mkdirs()
p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) }

p.apply plugin: 'com.android.application'
p.apply plugin: 'de.mannodermaus.android-junit5'
p.android {
compileSdkVersion COMPILE_SDK
buildToolsVersion BUILD_TOOLS

defaultConfig {
applicationId APPLICATION_ID
minSdkVersion MIN_SDK
targetSdkVersion TARGET_SDK
versionCode VERSION_CODE
versionName VERSION_NAME
}
}
p.junitPlatform {
// Some arbitrary non-existent version
jupiterVersion nonExistentVersion
}
p.repositories {
jcenter()
}
p.dependencies {
// "testCompile" or "testApi"
invokeMethod(testCompileDependency(), junitJupiter())
}

then:
// AGP 2.x throws a ModuleVersionNotFoundException here
try {
p.evaluate()
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")

} catch (Throwable expected) {
while (expected != null) {
if (expected instanceof ModuleVersionNotFoundException) {
assert expected.message.contains("Could not find org.junit.jupiter")
assert expected.message.contains("$nonExistentVersion")
break
}
expected = expected.cause
}

if (expected == null) {
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.mannodermaus.gradle.anj5

import org.gradle.api.Project
import org.gradle.internal.resolve.ArtifactResolveException
import org.gradle.internal.resolve.ModuleVersionNotFoundException
import org.gradle.testfixtures.ProjectBuilder

class AndroidJUnitPlatformAgp3xSpec extends AndroidJUnitPlatformSpec {
Expand All @@ -14,49 +16,4 @@ class AndroidJUnitPlatformAgp3xSpec extends AndroidJUnitPlatformSpec {
protected String testRuntimeDependency() {
return "testRuntimeOnly"
}

def "custom junit jupiter version"() {
when:
def nonExistentVersion = "0.0.0"

Project p = ProjectBuilder.builder().withParent(testRoot).build()
p.file(".").mkdir()
p.file("src/main").mkdirs()
p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) }

p.apply plugin: 'com.android.application'
p.apply plugin: 'de.mannodermaus.android-junit5'
p.android {
compileSdkVersion COMPILE_SDK
buildToolsVersion BUILD_TOOLS

defaultConfig {
applicationId APPLICATION_ID
minSdkVersion MIN_SDK
targetSdkVersion TARGET_SDK
versionCode VERSION_CODE
versionName VERSION_NAME
}
}
p.junitPlatform {
// Some arbitrary non-existent version
jupiterVersion nonExistentVersion
}
p.dependencies {
// "testCompile" or "testApi"
invokeMethod(testCompileDependency(), junitJupiter())
}

then:
p.evaluate()

def testApiDeps = p.configurations.getByName("testApi").dependencies
assert testApiDeps.find {
it.group == "org.junit.jupiter" && it.name == "junit-jupiter-api" && it.version == nonExistentVersion
} != null

assert testApiDeps.find {
it.group == "junit" && it.name == "junit" && it.version == "4.12"
} != null
}
}

0 comments on commit 8a5ae7c

Please sign in to comment.