Skip to content

Commit 8a5ae7c

Browse files
author
Marcel Schnelle
committed
Added some info logging & unified 2.x & 3.x test cases even further
1 parent adea3d6 commit 8a5ae7c

File tree

4 files changed

+68
-106
lines changed

4 files changed

+68
-106
lines changed

android-junit5/src/main/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformPlugin.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,10 @@ class AndroidJUnitPlatformPlugin extends JUnitPlatformPlugin {
172172
String nameSuffix = map.getOrDefault("nameSuffix", "")
173173
def dependentTasks = map.dependentTasks
174174

175+
project.logger.info("$LOG_TAG Creating JUnit 5 Task for variant '$nameSuffix'...")
176+
project.logger.info("$LOG_TAG Test Root Dirs: $testRootDirs")
177+
project.logger.info("$LOG_TAG Classpath: $classpath.asPath")
178+
175179
project.task(
176180
TASK_NAME + nameSuffix,
177181
type: JavaExec,

android-junit5/src/test/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformSpec.groovy

Lines changed: 62 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package de.mannodermaus.gradle.anj5
22

33
import org.gradle.api.Project
44
import org.gradle.api.internal.plugins.PluginApplicationException
5+
import org.gradle.internal.resolve.ModuleVersionNotFoundException
56
import org.gradle.testfixtures.ProjectBuilder
67
import spock.lang.Specification
78

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

179-
// println "---- $task.name"
180-
// classpath.each {
181-
// println " > $it"
182-
// }
180+
println "---- $task.name"
181+
classpath.each {
182+
println " > $it"
183+
}
183184

184185
// Source set's outputs
185186
assert classpath.find { it.contains("test/build/intermediates/classes/") } != null
@@ -284,4 +285,61 @@ abstract class AndroidJUnitPlatformSpec extends Specification {
284285
// (Project.logging listeners don't seem to work)
285286
assert true == true
286287
}
288+
289+
def "custom junit jupiter version"() {
290+
when:
291+
def nonExistentVersion = "0.0.0"
292+
293+
Project p = ProjectBuilder.builder().withParent(testRoot).build()
294+
p.file(".").mkdir()
295+
p.file("src/main").mkdirs()
296+
p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) }
297+
298+
p.apply plugin: 'com.android.application'
299+
p.apply plugin: 'de.mannodermaus.android-junit5'
300+
p.android {
301+
compileSdkVersion COMPILE_SDK
302+
buildToolsVersion BUILD_TOOLS
303+
304+
defaultConfig {
305+
applicationId APPLICATION_ID
306+
minSdkVersion MIN_SDK
307+
targetSdkVersion TARGET_SDK
308+
versionCode VERSION_CODE
309+
versionName VERSION_NAME
310+
}
311+
}
312+
p.junitPlatform {
313+
// Some arbitrary non-existent version
314+
jupiterVersion nonExistentVersion
315+
}
316+
p.repositories {
317+
jcenter()
318+
}
319+
p.dependencies {
320+
// "testCompile" or "testApi"
321+
invokeMethod(testCompileDependency(), junitJupiter())
322+
}
323+
324+
then:
325+
// AGP 2.x throws a ModuleVersionNotFoundException here
326+
try {
327+
p.evaluate()
328+
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")
329+
330+
} catch (Throwable expected) {
331+
while (expected != null) {
332+
if (expected instanceof ModuleVersionNotFoundException) {
333+
assert expected.message.contains("Could not find org.junit.jupiter")
334+
assert expected.message.contains("$nonExistentVersion")
335+
break
336+
}
337+
expected = expected.cause
338+
}
339+
340+
if (expected == null) {
341+
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")
342+
}
343+
}
344+
}
287345
}

android-junit5/src/testAgp2x/groovy/de/mannodermaus/gradle/anj5/AndroidJUnitPlatformAgp2xSpec.groovy

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -19,61 +19,4 @@ class AndroidJUnitPlatformAgp2xSpec extends AndroidJUnitPlatformSpec {
1919
protected String testRuntimeDependency() {
2020
return "testApk"
2121
}
22-
23-
def "custom junit jupiter version"() {
24-
when:
25-
def nonExistentVersion = "0.0.0"
26-
27-
Project p = ProjectBuilder.builder().withParent(testRoot).build()
28-
p.file(".").mkdir()
29-
p.file("src/main").mkdirs()
30-
p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) }
31-
32-
p.apply plugin: 'com.android.application'
33-
p.apply plugin: 'de.mannodermaus.android-junit5'
34-
p.android {
35-
compileSdkVersion COMPILE_SDK
36-
buildToolsVersion BUILD_TOOLS
37-
38-
defaultConfig {
39-
applicationId APPLICATION_ID
40-
minSdkVersion MIN_SDK
41-
targetSdkVersion TARGET_SDK
42-
versionCode VERSION_CODE
43-
versionName VERSION_NAME
44-
}
45-
}
46-
p.junitPlatform {
47-
// Some arbitrary non-existent version
48-
jupiterVersion nonExistentVersion
49-
}
50-
p.repositories {
51-
jcenter()
52-
}
53-
p.dependencies {
54-
// "testCompile" or "testApi"
55-
invokeMethod(testCompileDependency(), junitJupiter())
56-
}
57-
58-
then:
59-
// AGP 2.x throws a ModuleVersionNotFoundException here
60-
try {
61-
p.evaluate()
62-
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")
63-
64-
} catch (Throwable expected) {
65-
while (expected != null) {
66-
if (expected instanceof ModuleVersionNotFoundException) {
67-
assert expected.message.contains("Could not find org.junit.jupiter")
68-
assert expected.message.contains("$nonExistentVersion")
69-
break
70-
}
71-
expected = expected.cause
72-
}
73-
74-
if (expected == null) {
75-
throw new AssertionError("Expected ${ModuleVersionNotFoundException.class.name}, but wasn't thrown")
76-
}
77-
}
78-
}
7922
}
Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package de.mannodermaus.gradle.anj5
22

33
import org.gradle.api.Project
4+
import org.gradle.internal.resolve.ArtifactResolveException
5+
import org.gradle.internal.resolve.ModuleVersionNotFoundException
46
import org.gradle.testfixtures.ProjectBuilder
57

68
class AndroidJUnitPlatformAgp3xSpec extends AndroidJUnitPlatformSpec {
@@ -14,49 +16,4 @@ class AndroidJUnitPlatformAgp3xSpec extends AndroidJUnitPlatformSpec {
1416
protected String testRuntimeDependency() {
1517
return "testRuntimeOnly"
1618
}
17-
18-
def "custom junit jupiter version"() {
19-
when:
20-
def nonExistentVersion = "0.0.0"
21-
22-
Project p = ProjectBuilder.builder().withParent(testRoot).build()
23-
p.file(".").mkdir()
24-
p.file("src/main").mkdirs()
25-
p.file("src/main/AndroidManifest.xml").withWriter { it.write(ANDROID_MANIFEST) }
26-
27-
p.apply plugin: 'com.android.application'
28-
p.apply plugin: 'de.mannodermaus.android-junit5'
29-
p.android {
30-
compileSdkVersion COMPILE_SDK
31-
buildToolsVersion BUILD_TOOLS
32-
33-
defaultConfig {
34-
applicationId APPLICATION_ID
35-
minSdkVersion MIN_SDK
36-
targetSdkVersion TARGET_SDK
37-
versionCode VERSION_CODE
38-
versionName VERSION_NAME
39-
}
40-
}
41-
p.junitPlatform {
42-
// Some arbitrary non-existent version
43-
jupiterVersion nonExistentVersion
44-
}
45-
p.dependencies {
46-
// "testCompile" or "testApi"
47-
invokeMethod(testCompileDependency(), junitJupiter())
48-
}
49-
50-
then:
51-
p.evaluate()
52-
53-
def testApiDeps = p.configurations.getByName("testApi").dependencies
54-
assert testApiDeps.find {
55-
it.group == "org.junit.jupiter" && it.name == "junit-jupiter-api" && it.version == nonExistentVersion
56-
} != null
57-
58-
assert testApiDeps.find {
59-
it.group == "junit" && it.name == "junit" && it.version == "4.12"
60-
} != null
61-
}
6219
}

0 commit comments

Comments
 (0)