Skip to content

Instantly share code, notes, and snippets.

@brettwold
Last active February 10, 2016 18:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brettwold/b33df7021e074fdec545 to your computer and use it in GitHub Desktop.
Save brettwold/b33df7021e074fdec545 to your computer and use it in GitHub Desktop.
How to make RxJava threading run instantly in JUnit/Robolectric tests

Make RxJava Execute Immediately for JUnit Tests

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();
}
});
}
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