Android instrumented test no tests found

14,485

Solution 1

Please add the following into your build.gradle and put your test classes into androidTest folder

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

Solution 2

I recently tried the accepted answer, but it gave me a process crash error when trying to run. If you get this you should use:

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"

Source: Instrumentation run failed due to 'Process crashed.'

Solution 3

This post helped me, just rename your tests methods with "test...", like testMethod()

Solution 4

The typical cause of this can be seen as an exception in Logcat.

I had a specific issue regarding an instrumented multidex run on < API 21, I had to both install MultiDex on a subclass of androidx.test.runner.AndroidJUnitRunner, and override:

  • AndroidJUnitRunner::createTestRequestBuilder
  • TestRequestBuilder::createClassPathScanner
  • ClassPathScanner::getClassPathEntries with the implementation as:

    • Unzip and extract the dex files from the APK
    • Run dexlib2 to obtain the type names.
    • Convert from the type names to a readable format: Ljava/lang/String; -> java.lang.string

This is because ClassPathScanner uses dalvik.system.DexFile, which on API 16, only reads APKs, and then only reads classes.dex

Solution 5

Another reason to get this error message is when you have an Android App implemented with Java and test cases implemented with Kotlin. If that is the case, be sure you have the following lines in your gradle file:

apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
Share:
14,485
Serban Stoenescu
Author by

Serban Stoenescu

Updated on July 05, 2022

Comments

  • Serban Stoenescu
    Serban Stoenescu almost 2 years

    I am new to Android instrumented unit tests. I have a simple test that looks like this. This is in instrumented tests; before I really write an actual instrumented test, I just want to test a simple one:

    @RunWith(AndroidJUnit4.class)
    @SmallTest
    public class AddressBookKeepingInstrumentedTest {
    
    
        public static final String TEST_STRING = "This is a string";
        public static final long TEST_LONG = 12345678L;
    
        @Test
        public void test_simple() {
            assertEquals(2,1+1);
        }
    }
    

    When I run this, I get the following error:

    junit.framework.AssertionFailedError: No tests found in com.example.myfirstapp.AddressBookKeepingInstrumentedTest
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:191)
    at android.test.AndroidTestRunner.runTest(AndroidTestRunner.java:176)
    at android.test.InstrumentationTestRunner.onStart(InstrumentationTestRunner.java:554)
    at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:1729)
    
    Tests ran to completion.
    

    Gradle build passed with success before this. Any ideas why this is happening?

  • Serban Stoenescu
    Serban Stoenescu almost 8 years
    The classes are in the right folder. I added what you said, now I get another error:Test running failed: Unable to find instrumentation info for: ComponentInfo{com.example.myfirstapp.test/android.support.te‌​st.runner.AndroidJUn‌​itRunner} Empty test suite. What test suite is it talking about? I didn't create one.
  • Serban Stoenescu
    Serban Stoenescu almost 8 years
    Actually, the answer in this question helped further: stackoverflow.com/questions/39241640/…
  • Long Ranger
    Long Ranger almost 8 years
    Can this be helpful ? stackoverflow.com/questions/29930597/… I did not have the same error as you when I created a simple hello world project with your class. I can run it successfully.
  • Serban Stoenescu
    Serban Stoenescu almost 8 years
    Yes, that is actually what I did. I posted the wrong link in the comment. Thanks. Yes, it helped!
  • Imeshke
    Imeshke over 6 years