Giter Site home page Giter Site logo

rxpresso's Introduction

UNMAINTAINED

No maintainance is intended.

RxPresso CI status Download from Bintray Apache 2.0 Licence

Easy Espresso UI testing for Android applications using RxJava.

Description

RxPresso makes testing your presentation layer using RxJava as easy as a Unit test.

RxPresso uses Mockito to generate mocks of your repositories that you can use with RxPresso to control data in your Espresso tests. The binding with Espresso Idling resource is handled for you so Espresso will wait until the data you expect to inject in your UI has been delivered to you UI.

No more data you don't control in your Espresso test.

This project is in its early stages, feel free to comment, and contribute back to help us improve it.

Adding to your project

To integrate RxPresso into your project, add the following at the beginning of the build.gradle of your project:

buildscript {
    repositories {
        jcenter()
    }
    dependencies {
        androidTestCompile 'com.novoda:rxpresso:0.2.0'
    }
}

Simple usage

To generate a mocked repo simply use Mockito.

Example repository

public interface DataRepository {

    Observable<User> getUser(String id);

    Observable<Articles> getArticles();

}

Mocking this repository

DataRepository mockedRepo = Mockito.mock(DataRepository.class)

You should then replace the repository used by your activities by this mocked one. If you use Dagger or Dagger2 you can replace the module by a test one providing the mock. If your repo lives in the application class you can have a setter or user reflection to set it during tests. Any other option as long as your UI reads from the mocked repo.

Set up RxPresso in your tests

DataRepository mockedRepo = getSameRepoUsedByUi();

RxPresso rxpresso = RxPresso.from(mockedRepo);
Espresso.registerIdlingResources(rxPresso);

Use it to inject data in your UI

rxPresso.given(mockedRepo.getUser("id"))
           .withEventsFrom(Observable.just(new User("some name")))
           .expect(any(User.class))
           .thenOnView(withText("some name"))
           .perform(click());

Use it to inject data from local sources

Observable<User> testAssetObservable = testAssetRepo.getUser("id");

rxPresso.given(mockedRepo.getUser("id"))
           .withEventsFrom(testAssetObservable)
           .expect(any(User.class))
           .thenOnView(withText("some name"))
           .perform(click());

Use custom matchers

Observable<User> testAssetObservable = testAssetRepo.getUser("id");

rxPresso.given(mockedRepo.getUser("id"))
           .withEventsFrom(testAssetObservable)
           .expect(new RxMatcher<Notification<User>>() {
                   @Override
                   public boolean matches(Notification<User> actual) {
                       return actual.getValue().name().equals("some name");
                   }

                   @Override
                   public String description() {
                       return "User with name " + "some name";
                   }
           })
           .thenOnView(withText("some name"))
           .perform(click());

Use it to inject errors in your UI

rxPresso.given(mockedRepo.getUser("id"))
           .withEventsFrom(Observable.error(new CustomError()))
           .expect(anyError(User.class, CustomError.class))
           .thenOnView(withText("Custom Error Message"))
           .matches(isDisplayed());

Reset mocks between tests

rxPresso.resetMocks();

You can also use RxPresso with multiple repositories. Just setup using all the repositories your UI is using. The usage doesn't change RxPresso will detect from what repo the observable provided comes from and send the data to the correct pipeline.

Setup with multiple repositories

DataRepository mockedRepo = getSameRepoUsedByUi();
AnotherDataRepository mockedRepo2 = getSameSecondRepoUsedByUi();


RxPresso rxpresso = RxPresso.from(mockedRepo, mockedRepo2);
Espresso.registerIdlingResources(rxPresso);

Links

Here are a list of useful links:

  • We always welcome people to contribute new features or bug fixes, here is how
  • If you have a problem check the Issues Page first to see if we are working on it
  • Looking for community help, browse the already asked Stack Overflow Questions or use the tag: support-rxpresso when posting a new question

rxpresso's People

Contributors

dorvaryn avatar tasomaniac avatar ataulm avatar blundell avatar rock3r avatar albo1337 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.