Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
This repository was archived by the owner on Feb 11, 2022. It is now read-only.
/rxpressoPublic archive

Easy Espresso UI testing for Android applications using RxJava.

License

NotificationsYou must be signed in to change notification settings

novoda/rxpresso

Repository files navigation

No maintainance is intended.

RxPressoCI statusDownload from BintrayApache 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 usesMockito 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 UIhas 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 thebuild.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

publicinterfaceDataRepository {Observable<User>getUser(Stringid);Observable<Articles>getArticles();}

Mocking this repository

DataRepositorymockedRepo =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

DataRepositorymockedRepo =getSameRepoUsedByUi();RxPressorxpresso =RxPresso.from(mockedRepo);Espresso.registerIdlingResources(rxPresso);

Use it to inject data in your UI

rxPresso.given(mockedRepo.getUser("id"))           .withEventsFrom(Observable.just(newUser("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(newRxMatcher<Notification<User>>() {@Overridepublicbooleanmatches(Notification<User>actual) {returnactual.getValue().name().equals("some name");                   }@OverridepublicStringdescription() {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(newCustomError()))           .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

DataRepositorymockedRepo =getSameRepoUsedByUi();AnotherDataRepositorymockedRepo2 =getSameSecondRepoUsedByUi();RxPressorxpresso =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 theIssues Page first to see if we are working on it
  • Looking for community help, browse the already askedStack Overflow Questions or use the tag:support-rxpresso when posting a new question

[8]ページ先頭

©2009-2025 Movatter.jp