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

前端 未结 30 2033
有刺的猬
有刺的猬 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:34

    You need to provide default constructor for your test class, for example:

    package nilzor.myapp.tests;
    
    public class NilzorSomeTest extends ActivityUnitTestCase<ActivityYouWantToTest>{
        public NilzorSomeTest(){
            super(ActivityYouWantToTest.class);
        }
    
        @SmallTest
        public void testBlah(){
            assertEquals(1,1);
        }
    }
    

    about your other questions:

    1. No. My tests still run without any annotations, but I guess it's a good practice to have them. It allows you to specify size of tests to run. See What is the purpose of @SmallTest, @MediumTest, and @LargeTest annotations in Android? for more detail.

    2. Yes, you need "test" prefix. InteliJ gives "method never used" warning when there's no "test" prefix, and skips that method during test run.

    3. Yes. I have my tests organized into subpackages and it seems to be working well.

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

    In my case that problem was caused due to mistake in my code, actually that was in application class, so target activity wasn't opened and test output prints

    Empty test suite error

    I have tried run tests directly from terminal with adb shell am instrument -w -r -e package your.package -e debug false android.support.test.runner.AndroidJUnitRunner. With this it prints for you much more about exception.

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

    I had the same issue, and the reason was my test class did not have Test at the end of the class name!

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

    This article helped me: Empty test suite

    Basically I had to create a package - instrumentTest/java - under my src directory, and put all the tests there. Then I could execute these tests individually.

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

    I had a raw Java project where this was occurring. Simply Java + JUnit4. It definitely resides with something in your .idea/ or .iml files. I scrapped mine, re-imported, and finally the tests ran again.

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

    Obviously, you need a target device as to run your tests as they are instrumented tests. For some reasons, Android studio sometimes does not ask you to point to this target device and just prompt the "Empty Test Suite" message. There are different ways to fix this, here are a few :

    • run your main app and select a target device or

    • go to the Run (Run/Run.../Edit Configurations) configuration and modify the Deployement Target Options

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