Skip to content

Commit cb3767a

Browse files
Merge pull request #7 from zawadz88/bugfix/runner_1_4_0_compatibility
Bugfix/runner 1 4 0 compatibility Remove bintray upload scripts.
2 parents 2932acf + d0a3189 commit cb3767a

File tree

9 files changed

+53
-109
lines changed

9 files changed

+53
-109
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Here are some samples:
8585

8686
| XRunner version | Test runner version |
8787
|:------------------------------------------------------------------------:|:---------------------------------------:|
88+
| [X.Y.Z](https://github.com/stepstone-tech/AndroidTestXRunner/tree/X.Y.Z) | `androidx.test:runner:1.4.0` |
8889
| [2.1.0](https://github.com/stepstone-tech/AndroidTestXRunner/tree/2.1.0) | `androidx.test:runner:1.2.0` |
8990
| [2.0.0](https://github.com/stepstone-tech/AndroidTestXRunner/tree/2.0.0) | `androidx.test:runner:1.1.0` |
9091
| [1.0.0](https://github.com/stepstone-tech/AndroidTestXRunner/tree/1.0.0) | `com.android.support.test:runner:1.0.2` |

build.gradle

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,46 @@
11
// Top-level build file where you can add configuration options common to all sub-projects/modules.
22

33
buildscript {
4-
ext.KOTLIN_VERSION = '1.3.41'
5-
ext.ANDROID_GRADLE_PLUGIN_VERSION = '3.5.0'
6-
ext.DOKKA_VERSION = '0.9.17'
7-
ext.BINTRAY_VERSION = '1.8.4'
4+
ext.KOTLIN_VERSION = '1.5.21'
5+
ext.ANDROID_GRADLE_PLUGIN_VERSION = '7.0.1'
6+
ext.DOKKA_VERSION = '1.5.0'
87
repositories {
98
google()
10-
jcenter()
119
maven {
1210
url 'https://dl.bintray.com/kotlin/kotlin-eap'
1311
}
12+
mavenCentral()
1413
}
1514
dependencies {
1615
classpath "com.android.tools.build:gradle:$ANDROID_GRADLE_PLUGIN_VERSION"
1716
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$KOTLIN_VERSION"
18-
classpath "org.jetbrains.dokka:dokka-android-gradle-plugin:$DOKKA_VERSION"
19-
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$BINTRAY_VERSION"
17+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:$DOKKA_VERSION"
2018
}
2119
}
2220

2321
allprojects {
2422
repositories {
2523
google()
26-
jcenter()
24+
mavenCentral()
2725
}
2826
}
2927

3028
configure(allprojects) {
3129
ext {
3230
ANDROID_MIN_SDK_VERSION = 19
33-
ANDROID_TARGET_SDK_VERSION = 28
34-
ANDROID_COMPILE_SDK_VERSION = 28
31+
ANDROID_TARGET_SDK_VERSION = 30
32+
ANDROID_COMPILE_SDK_VERSION = 30
3533

36-
TEST_RUNNER_VERSION = '1.2.0'
34+
TEST_RUNNER_VERSION = '1.4.0'
3735
SUPER_REFLEKT_VERSION = '1.0.1'
3836

3937
// Sample app only
40-
TEST_RULES_VERSION = '1.2.0'
41-
TEST_EXT_VERSION = '1.1.1'
42-
TEST_ORCHESTRATOR_VERSION = '1.2.0'
43-
ESPRESSO_VERSION = '3.2.0'
38+
TEST_RULES_VERSION = '1.4.0'
39+
TEST_EXT_VERSION = '1.1.3'
40+
TEST_ORCHESTRATOR_VERSION = '1.4.0'
41+
ESPRESSO_VERSION = '3.4.0'
4442
APPCOMPAT_VERSION = '1.1.0'
45-
MATERIAL_VERSION = '1.1.0-alpha10'
43+
MATERIAL_VERSION = '1.1.0'
4644
CONSTRAINT_VERSION = '1.1.3'
4745
}
4846
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
3+
distributionUrl=https\://services.gradle.org/distributions/gradle-7.1.1-all.zip
44
zipStoreBase=GRADLE_USER_HOME
55
zipStorePath=wrapper/dists

xrunner-library/bintrayv1.gradle

Lines changed: 0 additions & 32 deletions
This file was deleted.

xrunner-library/build.gradle

Lines changed: 10 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
apply plugin: 'com.android.library'
22
apply plugin: 'kotlin-android'
3-
apply plugin: 'org.jetbrains.dokka-android'
3+
apply plugin: 'org.jetbrains.dokka'
44
apply plugin: 'maven-publish'
55

66
apply from: '../ktlint.gradle'
@@ -30,30 +30,6 @@ dependencies {
3030
implementation "de.jodamob.android:SuperReflect:$SUPER_REFLEKT_VERSION"
3131
}
3232

33-
dokka {
34-
outputDirectory = "$rootDir/docs"
35-
}
36-
37-
task dokkaJavadoc(type: org.jetbrains.dokka.gradle.DokkaAndroidTask) {
38-
delete "$buildDir/docs"
39-
40-
outputFormat = 'javadoc'
41-
outputDirectory = "$buildDir/docs"
42-
43-
externalDocumentationLink {
44-
url = new URL("https://developer.android.com/reference/")
45-
}
46-
47-
// Always recreate documentation
48-
outputs.upToDateWhen { return false }
49-
}
50-
51-
afterEvaluate {
52-
if (project.hasProperty("javadocJar")) {
53-
tasks.javadocJar.dependsOn dokkaJavadoc
54-
}
55-
}
56-
5733
ext {
5834
bintrayRepo = 'maven'
5935
bintrayName = 'android-test-xrunner'
@@ -74,28 +50,22 @@ ext {
7450
allLicenses = ["Apache-2.0"]
7551
}
7652

77-
78-
tasks.withType(Javadoc) {
79-
excludes = ['**/*.kt']
80-
}
81-
8253
task sourcesJar(type: Jar) {
8354
classifier = 'sources'
8455
from android.sourceSets.main.java.srcDirs
8556
}
8657

87-
task javadoc(type: Javadoc) {
88-
source = android.sourceSets.main.java.srcDirs
89-
classpath += project.files(android.getBootClasspath().join(File.pathSeparator))
58+
dokkaJavadoc.configure {
59+
dokkaSourceSets {
60+
named("main") {
61+
noAndroidSdkLink.set(false)
62+
}
63+
}
9064
}
9165

92-
task javadocJar(type: Jar, dependsOn: javadoc) {
93-
94-
// Always recreate documentation
95-
outputs.upToDateWhen { return false }
96-
66+
task javadocJar(type: Jar, dependsOn: dokkaJavadoc) {
9767
classifier = 'javadoc'
98-
from new File("$buildDir/docs")
68+
from "$buildDir/dokka/javadoc"
9969
}
10070

10171
publishing {
@@ -108,6 +78,7 @@ publishing {
10878

10979
groupId publishedGroupId
11080
artifactId artifact
81+
version libraryVersion
11182

11283
pom {
11384
packaging 'aar'
@@ -148,7 +119,5 @@ publishing {
148119
}
149120
}
150121
}
151-
// Bintray Upload
152-
apply from: 'bintrayv1.gradle'
153122

154123
publishToMavenLocal.dependsOn 'assembleRelease'

xrunner-library/src/main/java/com/stepstone/xrunner/AndroidJUnitXRunner.kt

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
package com.stepstone.xrunner
22

33
import android.os.Bundle
4+
import android.util.Log
5+
import androidx.test.internal.events.client.TestEventClient
46
import androidx.test.internal.runner.RunnerArgs
57
import androidx.test.internal.runner.TestRequestBuilder
6-
import androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener
78
import androidx.test.runner.AndroidJUnitRunner
8-
import android.util.Log
99
import com.stepstone.xrunner.internal.ARGUMENT_CLASS
1010
import com.stepstone.xrunner.internal.ARGUMENT_LIST_TESTS_FOR_ORCHESTRATOR
1111
import com.stepstone.xrunner.internal.ARGUMENT_NOT_CLASS
1212
import com.stepstone.xrunner.internal.ARGUMENT_NOT_PACKAGE
13+
import com.stepstone.xrunner.internal.ARGUMENT_ORCHESTRATOR_DISCOVERY_SERVICE
1314
import com.stepstone.xrunner.internal.ARGUMENT_PACKAGE
1415
import com.stepstone.xrunner.internal.ARGUMENT_TARGET_PROCESS
1516
import com.stepstone.xrunner.internal.OrchestratorListenerWrapper
@@ -33,7 +34,7 @@ open class AndroidJUnitXRunner : AndroidJUnitRunner() {
3334
companion object {
3435
private const val TAG = "XRunner"
3536

36-
private const val RUNNER_FIELD_ORCHESTRATOR_LISTENER = "orchestratorListener"
37+
private const val RUNNER_FIELD_TEST_EVENT_CLIENT = "testEventClient"
3738
private const val RUNNER_FIELD_RUNNER_ARGS = "runnerArgs"
3839
private const val RUNNER_METHOD_CREATE_TEST_REQUEST_BUILDER = "createTestRequestBuilder"
3940
private const val RUNNER_ARGS_FIELD_LISTENERS = "listeners"
@@ -61,13 +62,13 @@ open class AndroidJUnitXRunner : AndroidJUnitRunner() {
6162
}
6263

6364
override fun onStart() {
64-
val orchestratorListener = SuperReflect.on(this).get<OrchestratedInstrumentationListener>(RUNNER_FIELD_ORCHESTRATOR_LISTENER)
65+
val testEventClient = SuperReflect.on(this).get<TestEventClient>(RUNNER_FIELD_TEST_EVENT_CLIENT)
6566

6667
if (shouldUpdateTestSuiteForXRunner()) {
6768
val runCount = getXRunnerCountArgument(modifiedBundle)
68-
addXRunnerTestsWithOrchestrator(runCount, modifiedBundle, orchestratorListener)
69+
addXRunnerTestsWithOrchestrator(runCount, modifiedBundle, testEventClient)
6970
} else if (isXRunnerTestExecution(originalBundle)) {
70-
updateListenersBeforeXRunnerTestExecution(orchestratorListener)
71+
updateListenersBeforeXRunnerTestExecution(testEventClient)
7172
}
7273
super.onStart()
7374
}
@@ -87,7 +88,7 @@ open class AndroidJUnitXRunner : AndroidJUnitRunner() {
8788
@Suppress("DEPRECATION")
8889
private fun isPrimaryInstrumentationProcess(): Boolean = isPrimaryInstrProcess(originalBundle.getString(ARGUMENT_TARGET_PROCESS))
8990

90-
private fun addXRunnerTestsWithOrchestrator(runCount: Int, bundle: Bundle, orchestratorListener: OrchestratedInstrumentationListener) {
91+
private fun addXRunnerTestsWithOrchestrator(runCount: Int, bundle: Bundle, testEventClient: TestEventClient) {
9192
val testDescriptionFromBundle = getTestDescriptionFromBundle(bundle)
9293
val testsToRerun = getMethodTestArgumentsFromDescription(testDescriptionFromBundle)
9394

@@ -98,29 +99,33 @@ open class AndroidJUnitXRunner : AndroidJUnitRunner() {
9899
.flatMap { testArg -> (1 until runCount).map { createXRunnerTestDescription(testArg, it) }.asSequence() }
99100
.forEach {
100101
Log.d(TAG, "Adding '$it' to test suite")
101-
orchestratorListener.addTests(it)
102+
testEventClient.addTests(it)
102103
}
103104
}
104105

105106
private fun shouldUpdateTestSuiteForXRunner(): Boolean {
106107
val listTestsForOrchestrator = (originalBundle.getString(ARGUMENT_LIST_TESTS_FOR_ORCHESTRATOR, false.toString())!!).toBoolean()
107-
return listTestsForOrchestrator && isPrimaryInstrumentationProcess() && shouldUseXRunner(originalBundle)
108+
val testDiscoveryForOrchestratorV2Provided = !originalBundle.getString(ARGUMENT_ORCHESTRATOR_DISCOVERY_SERVICE).isNullOrEmpty()
109+
return isPrimaryInstrumentationProcess() &&
110+
(testDiscoveryForOrchestratorV2Provided || listTestsForOrchestrator) &&
111+
shouldUseXRunner(originalBundle)
108112
}
109113

110-
private fun updateListenersBeforeXRunnerTestExecution(orchestratorListener: OrchestratedInstrumentationListener) {
114+
private fun updateListenersBeforeXRunnerTestExecution(testEventClient: TestEventClient) {
111115
val runnerArgs = getRunnerArgsWithReflection()
112116
SuperReflect.on(runnerArgs).set(
113-
RUNNER_ARGS_FIELD_LISTENERS, mutableListOf<RunListener>(
117+
RUNNER_ARGS_FIELD_LISTENERS,
118+
mutableListOf<RunListener>(
114119
OrchestratorListenerWrapper(
115-
orchestratorListener,
120+
testEventClient.runListener!!,
116121
originalTestToRun
117122
)
118123
)
119124
)
120-
/* We need to set this listener to null as otherwise it would be added in AndroidJUnitRunner#addListeners()
125+
/* We need to set test event client to no-op as otherwise it would be added in AndroidJUnitRunner#addListeners()
121126
* and it would duplicate what SCXRunnerOrchestratorListenerWrapper is already doing.
122127
*/
123-
SuperReflect.on(this).set(RUNNER_FIELD_ORCHESTRATOR_LISTENER, null)
128+
SuperReflect.on(this).set(RUNNER_FIELD_TEST_EVENT_CLIENT, TestEventClient.NO_OP_CLIENT)
124129
}
125130

126131
private fun getRunnerArgsWithReflection() = SuperReflect.on(this).get<RunnerArgs>(RUNNER_FIELD_RUNNER_ARGS)

xrunner-library/src/main/java/com/stepstone/xrunner/internal/OrchestratorListenerWrapper.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
package com.stepstone.xrunner.internal
22

3-
import androidx.test.orchestrator.instrumentationlistener.OrchestratedInstrumentationListener
3+
import androidx.test.internal.events.client.OrchestratedInstrumentationListener
44
import org.junit.runner.Description
55
import org.junit.runner.Result
66
import org.junit.runner.notification.Failure
77
import org.junit.runner.notification.RunListener
88

99
/**
10-
* This is a wrapper for the original [OrchestratedInstrumentationListener] set in [android.support.test.runner.AndroidJUnitRunner].
10+
* This is a wrapper for the original [OrchestratedInstrumentationListener] set in [androidx.test.runner.AndroidJUnitRunner].
1111
* It's purpose is to report to Android Test Orchestrator correct XRunner test methods e.g.
1212
* if [com.stepstone.xrunner.AndroidJUnitXRunner] was originally triggered to run "com.android.foo.FooTest#testFoo_XRUNNER_RUN_1"
1313
* this class would make sure that [OrchestratedInstrumentationListener] would get a test description with "_XRUNNER_RUN_1" suffix.
1414
* This is because [com.stepstone.xrunner.AndroidJUnitXRunner] removes this suffix when running the test.
1515
*/
1616
class OrchestratorListenerWrapper(
17-
private val orchestratorListener: OrchestratedInstrumentationListener,
17+
private val orchestratorListener: RunListener,
1818
private val originalTestToRun: String?
1919
) : RunListener() {
2020

xrunner-library/src/main/java/com/stepstone/xrunner/internal/TestArgumentsProvider.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,20 @@
11
package com.stepstone.xrunner.internal
22

33
import android.os.Bundle
4+
import kotlin.math.max
45

56
private const val XRUNNER_DEFAULT_COUNT = "10"
67

78
fun getClassArgument(bundle: Bundle): String? = bundle.getString(ARGUMENT_CLASS)
89

910
fun isXRunnerTestExecution(bundle: Bundle): Boolean = isXRunnerTest(getClassArgument(bundle))
1011

11-
fun getXRunnerCountArgument(bundle: Bundle): Int = Math.max(
12+
fun getXRunnerCountArgument(bundle: Bundle): Int = max(
1213
bundle.getString(
1314
ARGUMENT_XRUNNER_COUNT,
1415
XRUNNER_DEFAULT_COUNT
15-
).toInt(), 0
16+
).toInt(),
17+
0
1618
)
1719

1820
fun shouldUseXRunner(bundle: Bundle): Boolean = !getXRunnerClassArgument(bundle).isNullOrEmpty() ||

xrunner-library/src/main/java/com/stepstone/xrunner/internal/XRunnerConstants.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ internal const val ARGUMENT_PACKAGE = "package"
66
internal const val ARGUMENT_NOT_PACKAGE = "notPackage"
77
internal const val ARGUMENT_TARGET_PROCESS = "targetProcess"
88
internal const val ARGUMENT_LIST_TESTS_FOR_ORCHESTRATOR = "listTestsForOrchestrator"
9+
internal const val ARGUMENT_ORCHESTRATOR_DISCOVERY_SERVICE = "testDiscoveryService"
910

1011
internal const val ARGUMENT_XRUNNER_CLASS = "xrunnerClass"
1112
internal const val ARGUMENT_XRUNNER_NOT_CLASS = "xrunnerNotClass"

0 commit comments

Comments
 (0)