相关疑难解决方法(0)

Android RxJava 2 JUnit测试 - android.os.Looper中的getMainLooper没有模拟RuntimeException

我在尝试为正在使用的演示者运行JUnit测试时遇到RuntimeException observeOn(AndroidSchedulers.mainThread()).

由于它们是纯JUnit测试而不是Android检测测试,因此它们无法访问Android依赖项,导致我在执行测试时遇到以下错误:

java.lang.ExceptionInInitializerError
    at io.reactivex.android.schedulers.AndroidSchedulers$1.call(AndroidSchedulers.java:35)
    at io.reactivex.android.schedulers.AndroidSchedulers$1.call(AndroidSchedulers.java:33)
    at io.reactivex.android.plugins.RxAndroidPlugins.callRequireNonNull(RxAndroidPlugins.java:70)
    at io.reactivex.android.plugins.RxAndroidPlugins.initMainThreadScheduler(RxAndroidPlugins.java:40)
    at io.reactivex.android.schedulers.AndroidSchedulers.<clinit>(AndroidSchedulers.java:32)
    …
Caused by: java.lang.RuntimeException: Method getMainLooper in android.os.Looper not mocked. See http://g.co/androidstudio/not-mocked for details.
    at android.os.Looper.getMainLooper(Looper.java)
    at io.reactivex.android.schedulers.AndroidSchedulers$MainHolder.<clinit>(AndroidSchedulers.java:29)
    ...


java.lang.NoClassDefFoundError: Could not initialize class io.reactivex.android.schedulers.AndroidSchedulers
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    …
Run Code Online (Sandbox Code Playgroud)

junit android unit-testing rx-java rx-java2

48
推荐指数
5
解决办法
2万
查看次数

标签 统计

android ×1

junit ×1

rx-java ×1

rx-java2 ×1

unit-testing ×1