Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/novoda/rxpresso
Easy Espresso UI testing for Android applications using RxJava.
https://github.com/novoda/rxpresso
android android-application espresso-tests novoda open-source rxjava rxpresso
Last synced: 25 days ago
JSON representation
Easy Espresso UI testing for Android applications using RxJava.
- Host: GitHub
- URL: https://github.com/novoda/rxpresso
- Owner: novoda
- License: other
- Archived: true
- Created: 2015-05-14T10:18:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-02T14:14:07.000Z (almost 7 years ago)
- Last Synced: 2024-08-03T17:09:17.181Z (4 months ago)
- Topics: android, android-application, espresso-tests, novoda, open-source, rxjava, rxpresso
- Language: Java
- Homepage:
- Size: 125 KB
- Stars: 363
- Watchers: 60
- Forks: 23
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
- awesome-android-testing - rxpresso
- awesome-rxjava - rxpresso - Easy Espresso UI testing for Android applications using RxJava. (Testing)
README
# UNMAINTAINED
No maintainance is intended.
# RxPresso [![CI status](https://ci.novoda.com/buildStatus/icon?job=rxpresso)](https://ci.novoda.com/job/rxpresso/lastBuild/console) [![Download from Bintray](https://api.bintray.com/packages/novoda/maven/rxpresso/images/download.svg)](https://bintray.com/novoda/maven/rxpresso/_latestVersion) [![Apache 2.0 Licence](https://img.shields.io/github/license/novoda/rxpresso.svg)](https://github.com/novoda/rxpresso/blob/master/LICENSE.txt)
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](http://mockito.org/) 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:
```groovy
buildscript {
repositories {
jcenter()
}
dependencies {
androidTestCompile 'com.novoda:rxpresso:0.2.0'
}
}
```## Simple usage
To generate a mocked repo simply use Mockito.
**Example repository**
```java
public interface DataRepository {Observable getUser(String id);
Observable getArticles();
}
```**Mocking this repository**
```java
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**
```java
DataRepository mockedRepo = getSameRepoUsedByUi();RxPresso rxpresso = RxPresso.from(mockedRepo);
Espresso.registerIdlingResources(rxPresso);
```**Use it to inject data in your UI**
```java
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**
```java
Observable testAssetObservable = testAssetRepo.getUser("id");rxPresso.given(mockedRepo.getUser("id"))
.withEventsFrom(testAssetObservable)
.expect(any(User.class))
.thenOnView(withText("some name"))
.perform(click());
```**Use custom matchers**
```java
Observable testAssetObservable = testAssetRepo.getUser("id");rxPresso.given(mockedRepo.getUser("id"))
.withEventsFrom(testAssetObservable)
.expect(new RxMatcher>() {
@Override
public boolean matches(Notification 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**
```java
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**
```java
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**
```java
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](https://github.com/novoda/novoda/blob/master/CONTRIBUTING.md)
* If you have a problem check the [Issues Page](https://github.com/novoda/rxpresso/issues) first to see if we are working on it
* Looking for community help, browse the already asked [Stack Overflow Questions](http://stackoverflow.com/questions/tagged/support-rxpresso) or use the tag: `support-rxpresso` when posting a new question