Robolectric 4 AndroidX NoClassDefFoundError MonitoringInstrumentation with IntelliJ 2018.3.4

Robolectric 4 AndroidX NoClassDefFoundError MonitoringInstrumentation with IntelliJ 2018.3.4

问题

没有重复问题:

我阅读了使用 google 或 Whosebug 搜索时弹出的其他主题,但它们是关于一个更具体的错误,可以通过添加特定的依赖项来解决。就我而言,我无法确定要添加哪个依赖项。

我读到 Android Studio 3.3 和 Robolectric 4.0 不需要解决方法。

  • 使用 Android Studio 3.3.1+ 和 Robolectric 4.0+

这对我有用。

我将依赖添加到 androidx.test:core 对于正在测试的构建类型。

在我的例子中是 debug 所以在 build.gradle 我添加

debugImplementation 'androidx.test:core:1.2.0'