Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

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.

question from:https://stackoverflow.com/questions/22582021/android-studio-no-tests-were-found

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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!");
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...