7

I have an android project where I use espresso to define tests. It all worked well until now but after upgrading to AppCompat 23.2.1 (from AppCompat 23.0.1) the execution of the tests always crashes.

My build.gradle dependencies:

dependencies {

// Ok Config
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
compile 'com.android.support:appcompat-v7:23.2.1'
compile 'com.android.support:design:23.2.1'
compile 'com.android.support:support-annotations:23.2.1'

androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
androidTestCompile 'com.android.support.test:runner:0.5'
androidTestCompile 'com.android.support:support-annotations:23.2.1'
androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.2'
androidTestCompile 'com.android.support.test.espresso:espresso-contrib:2.2.2'

The project compiles and executes ok, but when I try to run a test it crashes with this error:

java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity

Despite the text of the error I am using a descendant theme of Theme.AppCompat, so I don't understand the error message at all.

Anyone had the same problem? It seems to be any problem with the dependencies of appcompat and espresso, but I'm unable to find it and solve my problem.

Any ideas?

Thanks!

4
  • put your activity in manifest Mar 17, 2016 at 15:37
  • @KrupalShah the activity is in manifest. In fact, the app runs ok on normal executions but not in test executions. Should I add the manifest code to the question?
    – jaumebd
    Mar 17, 2016 at 15:50
  • @jaumebd Any update on this? Apr 4, 2016 at 2:02
  • @JaredBurrows take a look at my answer. I've posted the solution I've found. Hope this could help you
    – jaumebd
    Apr 5, 2016 at 11:54

1 Answer 1

18

I think that the main problem is that espresso modules use a different support library than the one used in my project, so when I try to run the test the tests crashes.

Finally I've resolved it excluding the support library of all the espresso modules, to force them to use the support library of my project. And now everything works great. Hope this could help anyone!

My gradle looks like this:

    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.android.support:support-annotations:23.2.1'


    androidTestCompile ('com.android.support.test:runner:0.5') {
        exclude group: 'com.android.support'
    }
    androidTestCompile ('com.android.support.test:rules:0.5') {
        exclude group: 'com.android.support'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-core:2.2.2') {
        exclude group: 'com.android.support'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-contrib:2.2.2') {
        exclude group: 'com.android.support'
    }
    androidTestCompile ('com.android.support.test.espresso:espresso-intents:2.2.2') {
        exclude group: 'com.android.support'
    }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.