I'm not sure what you're adding robolectric, mockito, etc.. on androidTestCompile. This configuration is used to build the test APK.
I don't know how the robolectric plugin does things right now, you might want to ask them instead. On Thu, Jan 29, 2015 at 8:42 AM, Xavier Gouchet <[email protected]> wrote: > Ok, so here's my setting (Android Studio 1.0.2, Gradle plugin 1.0.0). > > I have a library module on which I try to have Unit Tests. Because I need > those tests to be fast, I started using Robolectric, which was quite easy > to add to my project. Here's what my build.gradle looks like : > > > apply plugin: 'com.android.library' > apply plugin: 'robolectric' > > android { > compileSdkVersion 21 > buildToolsVersion "21.1.2" > > defaultConfig { > minSdkVersion 8 > targetSdkVersion 21 > versionCode 1 > versionName "0.10.16" > } > > compileOptions { > sourceCompatibility JavaVersion.VERSION_1_7 > targetCompatibility JavaVersion.VERSION_1_7 > } > > // Build Types configuration > buildTypes { > debug { > minifyEnabled false > debuggable true > testCoverageEnabled = true > } > > release { > minifyEnabled true > debuggable false > proguardFiles getDefaultProguardFile('proguard-android.txt'), > 'proguard-rules.cfg' > } > } > } > > dependencies { > // TEST LIBRARIES > androidTestCompile('junit:junit:4.11') > androidTestCompile('org.robolectric:robolectric:2.+') { > exclude module: 'classworlds' > exclude module: 'maven-artifact' > exclude module: 'maven-artifact-manager' > exclude module: 'maven-error-diagnostics' > exclude module: 'maven-model' > exclude module: 'maven-plugin-registry' > exclude module: 'maven-profile' > exclude module: 'maven-project' > exclude module: 'maven-settings' > exclude module: 'nekohtml' > exclude module: 'plexus-container-default' > exclude module: 'plexus-interpolation' > exclude module: 'plexus-utils' > exclude module: 'wagon-file' > exclude module: 'wagon-http-lightweight' > exclude module: 'wagon-http-shared' > exclude module: 'wagon-provider-api' > exclude group: 'com.android.support', module: 'support-v4' > exclude group: 'commons-logging' > exclude group: 'org.apache.httpcomponents' > } > > // MOCKING > androidTestCompile('org.mockito:mockito-core:1.10.19') > > // ASSERTS > androidTestCompile('org.assertj:assertj-core:1.7.0') > androidTestCompile('com.squareup.assertj:assertj-android:1.0.0') > > // have to add the support library for robolectric > androidTestCompile 'com.android.support:support-v4:21.0.3' > } > > > > > Problem is that I have a couple of classes using the NDK, so I must test > them on a device or emulator. So I added a couple of things to be able to > run Instrumented tests : > > > android { > > ... > defaultConfig { > ... > > testApplicationId "com.example.test" > testInstrumentationRunner "android.test.InstrumentationTestRunner" > } > > ... > > packagingOptions { > exclude 'META-INF/LICENSE.txt' > exclude 'META-INF/LICENSE' > exclude 'META-INF/NOTICE' > exclude 'LICENSE.txt' > exclude 'LICENSE' > exclude 'NOTICE' > exclude 'asm-license.txt' > } > } > > dependencies { > > ... > > // needed dependencies to use Mockito on a device > androidTestCompile 'com.google.dexmaker:dexmaker:1.0' > androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0' > > } > > > > Now the main issue I face is the dexMaker inclusions. They are necessary > to be able to use mockito on a device, but they break all my tests when > running Robolectric. > > What is the main cause is that both test system rely on the "androidTest" > flavor name (both sources are under the "androidTest/java" folder, and both > use the androidTestCompile keywords. Is there any way to create two test > flavors (lets say robolectricTest and InstrumentTest) so that each could > have their own dependencies ? > > -- > You received this message because you are subscribed to the Google Groups > "adt-dev" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/d/optout. > -- Xavier Ducrohet Android SDK Tech Lead Google Inc. http://developer.android.com | http://tools.android.com Please do not send me questions directly. Thanks! -- You received this message because you are subscribed to the Google Groups "adt-dev" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.
