mercredi 8 mars 2017

RuntimeEnvironment.application in Robolectric tests after AndroidStudio 3.3 update

We are using Robolectric for tests in Android Studio.

After a recent update from 2.2.x to 2.3 all my tests run with Robolectric (i.e. @RunWith(RobolectricTestRunner.class)) fail.

More specifically, I'm getting a ClassCastException here, as it seems that RuntimeEnvironment.application is no longer returning the custom application type created for test purposes.

MyTestApplication testApp = (MyTestApplication) RuntimeEnvironment.application;
// do something with testApp

Apparently I'm getting a plain old android.app.Application instead of the expected type...

The crux:

  • No tests nor config was changed, the only thing I did was the AndroidStudio update (I did git reset --hard just to make sure...).
  • On the command line my tests run fine.

:(

I think I tried just about everything in Android Studio, like clean/rebuild, resync gradle files, invalid cache + restart... I cleaned my local gradle cache and my local .m2 repo just to make sure, but to no avail... :(

Aucun commentaire:

Enregistrer un commentaire