Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Test running failed : No Test results

Hi i am trying to run the example instrumented test class in my project but everytime i run it i get this error:

Test running failed: no test results
Empty test suit

Here is my example intrumented test class

import org.junit.Assert.assertEquals
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Instrumented test, which will execute on an Android device.
 *
 * See [testing documentation](http://d.android.com/tools/testing).
 */
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
    @Test
    fun useAppContext() {
        // Context of the app under test.
        val appContext = androidx.test.platform.app.InstrumentationRegistry.getInstrumentation().context
        assertEquals("com.app", appContext.packageName)
    }
}

Here is my gradle build filefor tests:

android {
  compileSdkVersion 28
    defaultConfig {
        applicationId "com.app"
        minSdkVersion 21
        targetSdkVersion 28
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
        testInstrumentationRunnerArguments clearPackageData: 'true'

    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
    compileOptions {
        sourceCompatibility JavaVersion.VERSION_1_8
        targetCompatibility JavaVersion.VERSION_1_8
    }
    testOptions {
        execution 'ANDROID_TEST_ORCHESTRATOR'
    }
}

dependencies {

    def mockito = "2.18.3"
//android instrumental test
    androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
    androidTestImplementation 'androidx.test.ext:junit:1.1.0'
    androidTestImplementation 'androidx.test.ext:truth:1.1.0'
    androidTestImplementation 'androidx.test:core:1.1.0'
    androidTestImplementation 'androidx.test:runner:1.1.1'
    androidTestImplementation 'androidx.arch.core:core-testing:2.0.0'
    androidTestUtil 'androidx.test:orchestrator:1.1.1'

    androidTestImplementation 'com.jraska.livedata:testing-ktx:0.6.0'
    androidTestImplementation 'com.jraska.livedata:testing:0.6.0'

    androidTestImplementation "org.mockito:mockito-core:$mockito"
    androidTestImplementation "org.mockito:mockito-android:$mockito"
    androidTestImplementation "org.mockito:mockito-inline:$mockito"

    androidTestImplementation 'org.koin:koin-test:1.0.2'

    //unit test
    testImplementation 'junit:junit:4.12'
    testImplementation "org.mockito:mockito-core:$mockito"
    testImplementation "org.mockito:mockito-android:$mockito"
    testImplementation "org.mockito:mockito-inline:$mockito"
    testImplementation 'org.koin:koin-test:1.0.2'
    testImplementation 'androidx.test.ext:junit:1.1.0'
    testImplementation 'androidx.arch.core:core-testing:2.0.0'
    testImplementation 'com.jraska.livedata:testing-ktx:0.6.0'
    testImplementation 'com.jraska.livedata:testing:0.6.0'
    testImplementation 'androidx.test.ext:truth:1.1.0'
  }
}
like image 625
Jonathan Avatar asked Jan 12 '19 11:01

Jonathan


People also ask

What is runtime test in Android?

The suite is built using the Android testing framework. The runner is implemented as a single instrumentation test that executes the test package and parses the result log. The logs are taken directly from the device (logcat).

How do I get Android test coverage?

View test coverage To run tests with coverage, follow the same steps as described in Run tests, only instead of clicking Run , click Run test-name with coverage . In the Project window, this option might be hidden behind More Run/Debug.

What is Android test runner?

The test runner handles loading your test package and the app under test to a device, running your tests, and reporting test results. This test runner supports several common testing tasks, including the following: Writing JUnit tests. Accessing the app's context. Filtering tests.

What is test folder in Android Studio?

By default, Unit tests are written in src/test/java/ folder and Instrumentation tests are written in src/androidTest/java/ folder. Android studio provides Run context menu for the test classes to run the test written in the selected test classes.


2 Answers

Updating my Android Studio to version 3.3 AND removing

testOptions {
    execution 'ANDROID_TEST_ORCHESTRATOR'
}

worked

like image 51
Jonathan Avatar answered Oct 25 '22 09:10

Jonathan


You're entirely set up using AndroidX for testing, except for the test orchestrator. Instead of removing the test orchestrator (which is very useful), change

execution 'ANDROID_TEST_ORCHESTRATOR'

to

execution 'ANDROIDX_TEST_ORCHESTRATOR'

like image 30
Bob Liberatore Avatar answered Oct 25 '22 10:10

Bob Liberatore