Reputation: 1097
for a specific project we need to run both Espresso and Robolectric test suites but it seems that their dependencies seem to clash very badly.
Therefore my question, is it even possible to have them both or should we settle for another solution?
Our Gradle file:
apply plugin: 'com.android.application'
apply plugin: 'jacoco'
android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
targetSdkVersion 24
minSdkVersion 15
versionCode 1
versionName "1.0"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
debug {
testCoverageEnabled true
}
}
}
dependencies {
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.android.support:appcompat-v7:24.2.1'
compile 'com.android.support:design:24.2.1'
compile 'com.android.support:support-v4:24.2.1'
compile 'com.android.support:recyclerview-v7:24.2.1'
androidTestCompile 'junit:junit:4.12'
androidTestCompile "org.robolectric:robolectric:3.1.4"
compile ('com.github.nkzawa:socket.io-client:0.3.0')
}
Thanks in advance.
Upvotes: 0
Views: 1044
Reputation: 4972
You can have them both, but you need to separate them into separate test packages.
Your robolectric tests should belong to the test
package, while espresso tests should reside in the androidTest
. Your dependencies will also be prefixed according to the packages (i.e robolectric dependencies will be testCompile
, while espresso tests will be androidTestCompile
).
This split is required due to the nature of both robolectric and espresso tests. Robolectric being a unit testing framework has android sdk fully (to some extent) mocked which allows the execution of the tests in JVM, while espresso requires "real" android for tests to be executed.
This guide from google covers the test set up in more details.
Upvotes: 1