1

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

Xi 张熹
  • 10,492
  • 18
  • 58
  • 86
  • Which version of Robolectric are you using? – Steve C Mar 12 '17 at 07:11
  • It is working fine here on Robolectric 3.0 . Did you try doing 'Invalidate caches / restart' ? And did you try running it with gradlew on command line: `gradlew clean testDebug` ? – Aram Tchekrekjian Mar 12 '17 at 10:08
  • Thanks guys the comments helped. I was trying different versions. Please see my updates. – Xi 张熹 Mar 12 '17 at 16:48
  • Can you show an example of your test setup? If you run it from the command line do they succeed? – Eugen Martynov Mar 12 '17 at 22:43
  • If I do "./gradlew test", it works; but then it's no difference from running all at once from AS, which works too. Not sure what my test setup is, just the AS' default, I guess. – Xi 张熹 Mar 12 '17 at 23:45

1 Answers1

1

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: screenshot for working directory settings

I would also recommend to setup module directory as working directory by default: screenshot for default working directory

Eugen Martynov
  • 19,888
  • 10
  • 61
  • 114