1

I'm curious whether it's possible to run Google ML Kit in Robolectric unit tests. If I try, I get the following error:

java.lang.IllegalStateException: MlKitContext has not been initialized

The same test runs perfectly if I run it as an instrumented test (with AndroidJUnit4).

gabhor
  • 669
  • 9
  • 23
  • 1
    Could you try initializing MLKitContext in your robolectric test before every test case and deleting it after each test case? mlkitContext. = MlKitContext.initialize(ApplicationProvider.getApplicationContext()); and mlkitContext.delete(); – Chenxi Song Jan 12 '21 at 17:08
  • Thank you @ChenxiSong! I have no such error with your suggestion! Unfortunately, I still can't run my ML Kit implementation, because now I face another issue. I'll let you know once I could solve it. – gabhor Jan 18 '21 at 18:46

1 Answers1

0

Please use androidTest instead.

is the official answer from Google

ref: https://github.com/googlesamples/mlkit/issues/251

Gabor
  • 7,352
  • 4
  • 35
  • 56