Issue
I am using Android Studio 1.1.0. I am trying to separate my unit tests and integration tests. The integration tests are in folder src/androidTest/java. I am trying to create my unit tests in src/test/java/. This should be possible as per documentation.
Android Plug-in for Gradle version 1.1.0 and higher allows you to create a source directory (src/test/java) in your project to store JUnit tests that you want to run on a local machine.
My build.gradle dependencies look somewhat like this:
buildscript {
repositories {
jcenter()
mavenCentral()
}
dependencies {
classpath 'com.android.tools.build:gradle:1.2.3'
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
}
}
...
dependencies {
...
androidTestCompile 'junit:junit:4.12'
androidTestCompile 'org.mockito:mockito-all:1.9.5'
androidTestCompile 'org.mockito:mockito-core:1.10.19'
androidTestCompile files('libs/dexmaker-mockito-1.0.jar')
androidTestCompile files('libs/dexmaker-1.0.jar')
androidTestCompile 'org.hamcrest:hamcrest-core:1.1'
androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
androidTestCompile 'com.android.support.test:runner:0.3'
androidTestCompile ('com.android.support.test:testing-support-lib:0.1') {
exclude module: 'hamcrest-core'
}
androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2') {
exclude module: 'hamcrest-core'
}
}
This should work by all accounts but a sample test I wrote does not compile at all if I place it in src/test/java. It compiles and runs fine if I place it in src/androidTest/java. What am I missing? I cannot upgrade to Android Studio 1.2 at the moment. I have set my Test Artifact to Unit Test.
Solution
If you are using unit test then add your dependencies as testCompile ...
And you need to change your build variant.
Check http://tools.android.com/tech-docs/unit-testing-support
Answered By - isma3l
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.