Last active
February 10, 2016 18:17
-
-
Save brettwold/b33df7021e074fdec545 to your computer and use it in GitHub Desktop.
How to make RxJava threading run instantly in JUnit/Robolectric tests
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class BaseTestClass { | |
@Before | |
public void setup() { | |
ShadowLog.stream = System.out; | |
RxJavaTestPlugins.resetPlugins(); | |
RxJavaTestPlugins.getInstance().registerSchedulersHook(new RxJavaSchedulersHook() { | |
@Override | |
public Scheduler getIOScheduler() { | |
return Schedulers.immediate(); | |
} | |
@Override | |
public Scheduler getNewThreadScheduler() { | |
return Schedulers.immediate(); | |
} | |
}); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class RxJavaTestPlugins extends RxJavaPlugins { | |
RxJavaTestPlugins() { | |
super(); | |
} | |
public static void resetPlugins(){ | |
getInstance().reset(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment