I am developing an Android application using Kotlin programming language. I am writing instrumented tests for my application. I am also using the test orchestrator to run my instrumented tests. But after the installation of the test orchestrator modifying the Grandle file, I cannot run the test in the Android Studio.
I added the following configuration to the app.grandle file
android {
compileSdkVersion 29
buildToolsVersion "29.0.2"
defaultConfig {
applicationId "com.example.memento"
minSdkVersion 21
targetSdkVersion 29
versionCode 1
versionName "1.0"
// testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
testInstrumentationRunner "com.example.memento.MockTestRunner"
// Cleared between tests.
testInstrumentationRunnerArguments clearPackageData: 'true'
testOptions {
execution 'ANDROID_TEST_ORCHESTRATOR'
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}
}
With this
androidTestImplementation 'com.android.support.test:runner:1.1.1'
androidTestUtil 'com.android.support.test:orchestrator:1.1.1'
This is the MockTestRunner class
import android.app.Application import android.content.Context import androidx.test.runner.AndroidJUnitRunner import com.example.utils.MockApplicationController
class MockTestRunner: AndroidJUnitRunner()
{
override fun newApplication(
cl: ClassLoader?,
className: String?,
context: Context?
): Application {
return super.newApplication(cl, MockApplicationController::class.java!!.getName(), context)
}
}
Then, in the Android Studio, I tried to run a test by right-clicking on the code as follows.
This is what I got when I run the test.
$ adb shell CLASSPATH=$(pm path android.support.test.services) app_process / android.support.test.services.shellexecutor.ShellMain am instrument -r -w -e targetInstrumentation com.example.memento.test/com.example.memento.MockTestRunner -e debug false -e class 'com.example.memento.EventListTest#eventListIndexZeroTabRendersCurrentEvents' -e clearPackageData true android.support.test.orchestrator/android.support.test.orchestrator.AndroidTestOrchestrator
Waiting for process to come online...
Started running tests
Test running failed: No test results
Literally, not tests were run. What is wrong with my configuration and how can I fix it. If I remove the test orchestrator installation, I can run the tests and it is working as expected.