Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android instrumented test no tests found

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?

like image 405
Serban Stoenescu Avatar asked Aug 31 '16 05:08

Serban Stoenescu


People also ask

What is an instrumented test Android?

Instrumented tests run on Android devices, whether physical or emulated. As such, they can take advantage of the Android framework APIs. Instrumented tests therefore provide more fidelity than local tests, though they run much more slowly.

What is the difference between unit tests and instrumented tests?

Unit tests are useful for testing code which doesn't call the Android API, and the Android instrumentation tests are rather integration tests to test Android API specific elements or GUI components.

What is AndroidX test?

AndroidX Test is a collection of Jetpack libraries that lets you run tests against Android apps. It also provides a series of tools to help you write these tests. For example, AndroidX Test provides JUnit4 rules to start activities and interact with them in JUnit4 tests.


1 Answers

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

android {
    defaultConfig {
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
}
like image 133
Long Ranger Avatar answered Sep 21 '22 15:09

Long Ranger