Skip to content

Commit 4441758

Browse files
committed
Instrumentation Runner: Fix optional annotation detection & improve logging
1 parent 60de258 commit 4441758

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

instrumentation-runner/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ android {
6161

6262
dependencies {
6363
implementation "org.jetbrains.kotlin:kotlin-stdlib:$KOTLIN_VERSION"
64+
implementation "org.jetbrains.kotlin:kotlin-reflect:$KOTLIN_VERSION"
6465
implementation "junit:junit:$JUNIT4_VERSION"
6566

6667
// This module's JUnit 5 dependencies cannot be present on the runtime classpath,

instrumentation-runner/src/main/kotlin/de/mannodermaus/junit5/RunnerBuilder.kt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import org.junit.runners.model.RunnerBuilder
88

99
private const val LOG_TAG = "AndroidJUnit5"
1010
private val jupiterTestAnnotations = listOf(
11-
org.junit.jupiter.api.Test::class.java,
12-
org.junit.jupiter.api.TestFactory::class.java,
13-
org.junit.jupiter.params.ParameterizedTest::class.java)
11+
"org.junit.jupiter.api.Test",
12+
"org.junit.jupiter.api.TestFactory",
13+
"org.junit.jupiter.params.ParameterizedTest")
1414

1515
/* Types */
1616

@@ -34,7 +34,6 @@ class AndroidJUnit5Builder : RunnerBuilder() {
3434
private val junit5Available by lazy {
3535
try {
3636
Class.forName("org.junit.jupiter.api.Test")
37-
Class.forName("org.junit.jupiter.params.ParameterizedTest")
3837
Class.forName("de.mannodermaus.junit5.AndroidJUnit5")
3938
true
4039
} catch (e: Throwable) {
@@ -52,7 +51,6 @@ class AndroidJUnit5Builder : RunnerBuilder() {
5251
if (!testClass.hasJupiterTestMethods()) {
5352
return null
5453
}
55-
5654
return createJUnit5Runner(testClass)
5755

5856
} catch (e: NoClassDefFoundError) {
@@ -74,12 +72,14 @@ class AndroidJUnit5Builder : RunnerBuilder() {
7472
// Check each method in the Class for the presence
7573
// of the well-known list of JUnit Jupiter annotations
7674
val testMethod = declaredMethods.firstOrNull { method ->
75+
val annotationClassNames = method.declaredAnnotations.map { it.annotationClass.qualifiedName }
7776
jupiterTestAnnotations.firstOrNull { annotation ->
78-
method.isAnnotationPresent(annotation)
77+
annotationClassNames.contains(annotation)
7978
} != null
8079
}
8180

8281
if (testMethod != null) {
82+
Log.i(LOG_TAG, "Jupiter Test Class detected: ${this.name}")
8383
return true
8484
}
8585

@@ -91,7 +91,7 @@ class AndroidJUnit5Builder : RunnerBuilder() {
9191
}
9292

9393
} catch (t: Throwable) {
94-
Log.w(LOG_TAG, "$t in hasTestMethods for $name")
94+
Log.w(LOG_TAG, "${t.javaClass.name} in 'hasJupiterTestMethods()' for $name", t)
9595
}
9696

9797
return false

instrumentation/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ android {
1111
targetSdkVersion TARGET_SDK_VERSION
1212
versionCode 1
1313
versionName "1.0"
14+
multiDexEnabled true
1415

1516
// Usually, this is automatically applied through the Gradle Plugin
1617
testInstrumentationRunnerArgument "runnerBuilder", "de.mannodermaus.junit5.AndroidJUnit5Builder"

0 commit comments

Comments
 (0)