Gradle not building simple test in Android Studio


I’m having a problem running an android test for any project created in Android Studio.

For example, I’ve created new project with epmty Activity, tried running “ExampleInstrumentedTest” (which is created by default) and got this error:

Execution failed for task ':app:testDebugUnitTest'.
> No tests found for given includes: [com.example.test.ExampleInstrumentedTest.useAppContext](filter.includeTestsMatching)

build.gradle(:app) contains necessary imports, such as AndroidJUnitRunner in defaultConfig, junit:4.12, runner and espresso in dependencies.


Check what you have

android {
    sourceSets { + 'src/test/java/your_package_name' + 'src/androidTest/java/your_package_name'

in your app:gradle file.

Also check what your tests is in this folders.

Another important thing: sometimes Android Studio interpret Instrumented tests as Unit tests.

Check what your test icon in selected “Run configurations” looks like “Android logo with arrows”.

If it’s false:

  1. Click on “Edit configuration” of your test

  2. Click + in top left corner and add new Instrumented test.

  3. Select module and select Class which you will test

  4. (you can also remove all tests except it in Android Instrumented Test and Android JUnit in the left side)

PS: also check what test have @Test annotation 🙂

Answered By – Peter Staranchuk

Leave a Comment