2

Hello I'm trying to get ActionBar Activity UnitTests going and I'm using Robolectirc-RC2, but when i try to sync my android studio I'm getting the following error/warning. Warning:Conflict with dependency org.hamcrest:hamcrest-core. Resolved versions for app and test app differ. Any idea how to resolve it?

repositories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
mavenLocal()
mavenCentral()

}

dependencies {
// Unit testing dependencies
unitTestCompile('junit:junit:4.12') { // Prevent duplication conflicts
    exclude module: 'hamcrest-core'
    exclude module: 'hamcrest-library'
    exclude module: 'hamcrest-integration'
}
unitTestCompile 'org.hamcrest:hamcrest-core:1.1'
unitTestCompile 'org.hamcrest:hamcrest-library:1.1'
unitTestCompile 'org.hamcrest:hamcrest-integration:1.1'
unitTestCompile 'com.squareup.assertj:assertj-android:1.0.0'
Abhishek Ghosh
  • 2,593
  • 3
  • 27
  • 60

2 Answers2

4

ok the solution was to add the following code.

configurations.all {
resolutionStrategy {
    force 'org.hamcrest:hamcrest-core:1.3'
}}

and then replace per How can we access context of an application in Robolectric? Just use for version 1.x and 2.x:

Robolectric.application;

And for version 3.x:

RuntimeEnvironment.application;

additionally replace

Config(emulateSdk = 18, reportSdk = 18, manifest = "src/test/AndroidManifest.xml")

with

@Config(sdk = 18)

Community
  • 1
  • 1
  • I tried using resolutionStrategy without success (same error, different libs). I was able to get it to compile simply by adding compile 'org.hamcrest:hamcrest-core:1.3' just above adding the dependency in question - in this case Robolectric. In my case it was for sendgrid – Nick Dec 07 '16 at 19:39
1

Here is how we specify Robolectric in our projects:

   testCompile("org.robolectric:robolectric:${robolectricVer}") {
        exclude group: 'commons-logging', module: 'commons-logging'
        exclude group: 'org.apache.httpcomponents', module: 'httpclient'
    }
Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114
  • I've made the changes above and now android studio can not find junit jar file and i'm getting some errors. error: package org.robolectric.annotation does not exist import org.robolectric.annotation.Config; – Andrei Chernyshev May 21 '15 at 19:13
  • It would be easy if you share your whole build.gradle file and project structure – Eugen Martynov May 22 '15 at 05:29