square / assertj-android

A set of AssertJ helpers geared toward testing Android.
https://square.github.io/assertj-android/
Apache License 2.0
1.58k stars 156 forks source link

Trouble importing org.assertj.android using Android Studio 1.1.0-Beta4 Unit Tests #150

Closed shekibobo closed 9 years ago

shekibobo commented 9 years ago

I have recently tried switching to Android Studio's native unit testing (switching from robolectric-gradle-plugin).

The relevant part of my gradle file is as follows:

dependencies {
    compile 'com.android.support:support-v4:21.+'
    compile 'com.android.support:appcompat-v7:21.+'
    compile 'com.google.android.gms:play-services-base:6.+'

    // robolectric
    testCompile 'junit:junit:[4,)'
    testCompile('org.robolectric:robolectric:3.+') {
        exclude group: 'commons-logging'
        exclude group: 'org.apache.httpcomponents'
    }

    testCompile('com.squareup.assertj:assertj-android:1.0.+') {
        exclude group: 'com.android.support'
    }
    testCompile('com.squareup.assertj:assertj-android-support-v4:1.0.+') {
        exclude group: 'com.android.support'
    }
    testCompile 'nl.jqno.equalsverifier:equalsverifier:1.4.1'
    testCompile 'org.mockito:mockito-core:2.0.+'

    // espresso
    androidTestCompile 'org.hamcrest:hamcrest-library:1.1'
    androidTestCompile 'org.hamcrest:hamcrest-integration:1.1'
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.0'
    androidTestCompile 'com.android.support.test:testing-support-lib:0.1'

When running the tests from either command line or within Android Studio, org.assertj.android cannot be resolved, despite no problems with the gradle sync.

Android Studio's autocomplete seems to be able to resolve org.assertj.core, but not org.assertj.android, so that shows as an error as well.

I'm not sure if this is a bug on assertj-android or on Android Studio, or as has been suggested in IRC, that assertj-android can't be used for unit tests (despite working fine with robolectric using the robolectric-gradle-plugin).

WojciechKo commented 9 years ago

I have simmilar problem. fest-android works fine, but after switch to assertj-android, I can't import org.assertj.android

commonquail commented 9 years ago

This is probably a duplicate of #129. I'm not using the Android Studio Robolectric plugin, which may or may not fix the issue, but @jhansche's work-around works for me:

dependencies {
    ...
    androidTestCompile 'com.squareup.assertj:assertj-android:1.0.0'
    androidTestCompile project.files("$project.buildDir/intermediates/exploded-aar/com.squareup.assertj/assertj-
android/1.0.0/classes.jar")
    ...
}

Because I currently depend on https://github.com/JCAndKSolutions/android-unit-test/, I'm actually using testCompile instead of androidTestCompile. Unfortunately, that creates a circular dependency: the required classes.jar is not created unless the build succeeds, and the build can't succeed because of the missing dependency. This is a bootstrapping problem that manifests itself whenever an action similar to clean is performed. I resolve it by changing testCompile to compile and carrying out a single successful build after any such destructive action, then change back the directives. I don't know if this issue exists with androidTestCompile.

JakeWharton commented 9 years ago

This is http://b.android.com/66841. Nothing wrong with the project itself.