> I have ported a rather big app to RxJava2, it...
# rx
d
I have ported a rather big app to RxJava2, it compiles and runs, but my unit tests which depend on rx all are failing with this error: java.lang.NoClassDefFoundError: Could not initialize class io.reactivex.android.schedulers.AndroidSchedulers
I kinda figured this out, but still don't know what happens. So if I call this in
@BeforeClass
in my unit tests:
Copy code
fun injectTestingRxSchedulers() {
  RxJavaPlugins.reset()
  RxJavaPlugins.setInitComputationSchedulerHandler { Schedulers.trampoline() }
  RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() }
  RxAndroidPlugins.reset()
  RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
  RxAndroidPlugins.setMainThreadSchedulerHandler { Schedulers.trampoline() }
}
I receive a class def not found errors and also exception-in-initializer errors. But if I strip it down to only
Copy code
fun injectTestingRxSchedulers() {
//  RxJavaPlugins.reset()
//  RxJavaPlugins.setInitComputationSchedulerHandler { Schedulers.trampoline() }
//  RxJavaPlugins.setComputationSchedulerHandler { Schedulers.trampoline() }
  RxAndroidPlugins.reset()
  RxAndroidPlugins.setInitMainThreadSchedulerHandler { Schedulers.trampoline() }
  RxAndroidPlugins.setMainThreadSchedulerHandler { Schedulers.trampoline() }
}
then no exceptions are thrown! So this is not a class path error. But some tricky hook-related one, I don't know them that well...