Reputation: 1304
I'm trying to test my class with InstrumentationTestCase. I've been checking the examples but I guess I'm missing something because "Test Artifact" dropdown is disabled and cannot be changed to JUNit.
I declared the libraries in gradle
// Test Compile
testCompile 'junit:junit:4.12'
testCompile 'org.robolectric:robolectric:2.4'
testCompile 'org.mockito:mockito-core:1.9.5'
testCompile 'org.reflections:reflections:0.9.9'
declared app id,
defaultConfig {
testApplicationId "myproject.android.test"
}
and getting the latest gradle version
dependencies {
classpath 'com.android.tools.build:gradle:+'
}
also created a build configuration for my test package. But when I run the test it gives me
Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
probably because Test Artifact is "Android Instrumentation Tests" and the build configuration is JUNit configuration. Test Artifact dropdown is disabled so I cannot change it to JUNit. Is there something that I'm missing?
Edit: my package tree is like this,
myproject
- app
- main
- java
-myproject
-android
-mypackage
-myclass.java
-test
-java
-myproject
-android
-mypackage
-test
-myclasstest.java
and in Android Studio preferences, under Gradle->Experimental, "Enable Unit Testing support" is checked.
Upvotes: 1
Views: 1625
Reputation: 10205
You need to do a few steps to activate JVM unit tests in Android Studio. Follow this steps: https://sites.google.com/a/android.com/tools/tech-docs/unit-testing-support
Upvotes: 3