Android Studio "No tests were found"

Has anyone been able to get tests to run in Android Studio (from the GUI and not terminal), I have been unable to run tests from the GUI.

Everytime I try to run tests through the GUI I just get the following message:

enter image description here

I am able to run the tests from terminal using the following command:

./gradlew connectedAndroidTest

I am running Android Studio 0.5.2 with Gradle 1.11 with Plugin 0.9.0 on Mac OSX

My project structure is as follows;

MyProject/
   src/
      androidTest/
         java/
             com.myproject.app.test/
                … (tests source code) …
      main/
         java/
             com.myproject.app/
                … (source code) …
         res/
                … (resources code) …
   build.gradle

My build.gradle file looks similar to the following:

…
android {
    compileSdkVersion 19
    buildToolsVersion "19.0.1"

    defaultConfig {
        versionCode 12
        versionName "2.0"
        minSdkVersion 9
        targetSdkVersion 19       
    testPackageName "com.test.foo"
        testInstrumentationRunner "android.test.InstrumentationTestRunner"
    }
}
…

If anyone has any suggestions, I will be more than happy to here them.


Today I had the same problem with some Espresso tests and it was getting me crazy because everything seemed normal. Finally I discovered the problem was because the method annotated with @BeforeClass was throwing an exception. If something goes wrong in that method, the stacktrace of the exception is not shown in the Log window of the Run tab but in the Log window of the Android Monitor tab

If you want to reproduce the problem just add this to your testing class:

@BeforeClass
public static void setupClass() {
    throw new RuntimeException("Sorry dude, you won't find any test!");
}

This can happen when the type of your run configuration is incorrect.

With me, this goes wrong when running an Espresso test which used to be a unit test. For some reason it still uses the Android JUnit test configuration when running this test. Manually creating an Android Instrumented Test solves the problem.