My Android project has about ~70 Robolectric tests and they were all passing for 2 months. Somehow, starting today, the tests are failing with weird error messages:
- java.lang.IllegalStateException: You need to use a Theme.AppCompat theme (or descendant) with this activity.
- java.lang.NoClassDefFoundError: org/apache/http/client/HttpClient
- Also can't load resource files
I didn't change my code, so it can't be code related issue. I cleaned project and gradle but it didn't help. I did do a update promoted by Android Studio a few days ago, not sure if related.
Is anyone else is experiencing the issue? How do I get out of this bad state?
-- edit --
Robolectric version matters! Interesting observation based on suggestions in comments, robolectric version v.s. failure rate:
- 3.3.1, ~40% of the tests fail.
- 3.2.2, ~40% failure (same as 3.3.1)
- 3.1.4, ~15% failure
- 3.1.2, ~0% failure (with caveats, see below)
- 3.1, 100% failure (!)
Another observation is that it's inconsistent. If I run the whole set, all pass! But If I only run one test file, all fail with this message:
No such manifest file: build/intermediates/bundles/debug/AndroidManifest.xml
AS is quite sensitive about dependencies change, as well AS doesn't set the working directory for tests by default.
No such manifest ...error directly saying that Robolectric can not find your manifest.Whenever you have test failing in AS check first the command line run if it is reproducible.
Check first working directory for test:
I would also recommend to setup module directory as working directory by default: