Why is the Android test runner reporting “Empty test suite”?

前端 未结 30 2035
有刺的猬
有刺的猬 2020-11-28 07:59

I am banging my head against the wall here trying to figure out why IntelliJ/Android is reporting \"Empty test suite\". I have a small project with two IntelliJ Modules (\"

相关标签:
30条回答
  • 2020-11-28 08:31

    I did nothing and the problem went away after half a day of pain, I opened and closed the projects many times, ran each class tests manually, maybe that fixed my it.

    0 讨论(0)
  • 2020-11-28 08:31

    I experienced the "Empty test suite" error when trying to run local unit tests in my Android Studio 3.0 project.

    After reading the Android Developer documentation, I quickly realised that the issue was caused by my gradle config which included the following lines.

    testImplementation 'com.android.support.test:runner:0.5'
    testImplementation 'com.android.support.test:rules:0.5'
    

    The AndroidJUnitRunner class is a JUnit test runner that lets you run JUnit 3- or JUnit 4-style test classes on Android devices.

    Since my tests were local and therefore not required to run on any device, removing the above com.android.support.test... entries enabled me to execute the unit tests.

    0 讨论(0)
  • 2020-11-28 08:32

    I had this problem because I had this in my build.gradle:

    testOptions {
        execution "ANDROID_TEST_ORCHESTRATOR"
    }
    

    Even though I wasn't using the Android Test Orchestrator (must have copyied from the tutorials by mistake).

    Commenting that out solved it for me.

    0 讨论(0)
  • 2020-11-28 08:32

    In my case, none of the previous answers worked. The solution was to simply move the test class to another package.

    This happened under androidTest/

    0 讨论(0)
  • 2020-11-28 08:32

    In my case, the project I was working on had a couple of modules. None of the solutions I found for this error helped me, and then somehow I realized that if I added the testing dependencies in BOTH of the build.gradle files, the tests magically started working. It doesn't matter if your tests live in only 1 of the modules, both gradle files must include the dependencies and the testInstrumentationRunner value.

    So, if like me, none of the other answers have helped you, try adding these lines to the build.gradle file of each of your modules:

    android {    
        ....
        defaultConfig {
            ...
            testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        }  
    }
    

    and then also add:

    dependencies {
        ...
        // Test
        androidTestCompile 'com.android.support:support-annotations:23.4.0'
        androidTestCompile 'com.android.support.test:runner:0.5'
        androidTestCompile 'com.android.support.test:rules:0.5'
    
    }
    
    0 讨论(0)
  • 2020-11-28 08:33

    Not a solution but a workaround that will get you back on track quickly:

    1. Firstly, find a test that works. I was writing a new test where I got the 'empty test suite' error. I ran other tests and they were working as usual.

    2. Copy the test file that does work. Run it to make sure this copy works like the original.

    3. Remove the body and replace it with your new test code.

    The test should now work.

    We spent about two hours trying to find the cause but to no avail.

    0 讨论(0)
提交回复
热议问题