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:
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.
Just for posterity sakes, here's the solution that worked for me -
The error you're seeing happens if AS for some reason thinks that the test that you're about to run is a unit and not an instrumentation test. Often this error goes away buy just clicking on the package instead of the actual class.
Found at https://github.com/googlecodelabs/android-testing/issues/27#issuecomment-219074863
I just ran the tests by right clicking on the package name and choosing "Run 'Tests in {packageName}'" and it worked.
Ok, I found the cause of my problem.
In the misc.xml file which is located in the .idea folder of my project had an invalid attribute value for the ProjectRootManager component, which looked like the following:
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6 (3)" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
So changing the project-jdk-name
attribute value to just "1.6", fixed the problem for me. Below is what it looked like after I had updated the value.
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_6" assert-keyword="true" jdk-15="true" project-jdk-name="1.6" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
Hope this helps anyone out.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With