• This repository has been archived on 11/Feb/2022
  • Stars
    star
    363
  • Rank 113,068 (Top 3 %)
  • Language
    Java
  • License
    Other
  • Created almost 9 years ago
  • Updated about 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Easy Espresso UI testing for Android applications using RxJava.

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

More Repositories

1

android-demos

Examples of Android applications
Java
1,984
star
2

bintray-release

A helper for releasing from gradle up to bintray
Groovy
1,857
star
3

bonfire-firebase-sample

An app to discuss your favourite emojis. This is a sample app built with Firebase.
Java
549
star
4

merlin

Observes network connection status & gives callbacks
Java
544
star
5

spikes

Where ideas & concepts are born & incubated
Java
543
star
6

download-manager

A library that handles long-running downloads, handling the network interactions and retrying downloads automatically after failures
Java
487
star
7

gradle-static-analysis-plugin

Easy setup of static analysis tools for Android and Java projects.
Groovy
408
star
8

gradle-android-command-plugin

Handy commands for testing Android on CI
Groovy
358
star
9

sqlite-provider

Extended SQLite functionality for Android
Java
303
star
10

no-player

Simplified Player wrapper for MediaPlayer and ExoPlayer
Java
181
star
11

simple-chrome-custom-tabs

Easy integration of Chrome Custom Tabs into your project. Just connect it to your activity, and navigate to the external website styling your tab as you wish.
Java
129
star
12

notils

Never again need a .utils. package yur scurvy sea dogs!
Java
122
star
13

gradle-build-properties-plugin

Keep your secrets secret. External build properties support for your Gradle scripts.
Groovy
112
star
14

ios-demos

Examples of ios applications http://www.novoda.com/blog
Swift
95
star
15

accessibilitools

UI tools to help make your Android app accessible.
Java
81
star
16

dojos

This is where the Novoda team do all their hacking
Java
76
star
17

simple-easy-xml-parser

Simple XML Parsing into Domain Objects
Java
69
star
18

sqlite-analyzer

Code generation for Java/Android database access.
Java
64
star
19

spritz

Spritz is an Android library to seamlessly trigger a Lottie animation
Java
62
star
20

espresso-support

Includes custom rules for testing Views in isolation and running tests with Google TalkBack enabled.
Java
60
star
21

novoda

Common things for all Novoda's open source projects
Java
37
star
22

view-pager-adapter

A simple implementation of PagerAdapter that supports Views.
Java
29
star
23

aosp.changelog.to

Generates a change log between different aosp tags. Based on the wonderful work of @alsutton
HTML
15
star
24

droidcon-booth

Novoda will be showing you CI in action at our Droidcon London booth!
Java
14
star
25

landing-strip

Your simple sliding viewpager tab strip: a landing strip without the fluff!
Java
13
star
26

novoda.github.io

GitHub open source landing page
SCSS
11
star
27

dashboards

The dashboards we have running in our offices!
JavaScript
10
star
28

drop-cap

Custom DropCap view without Spans
Java
10
star
29

public-mvn-repo

Novoda Public Maven Central Repository
7
star
30

github-reports

Github reports for a given organisation
Java
5
star
31

ncu

Novoda Craft University
3
star
32

peepz

Java
3
star
33

eslint-config-novoda

JavaScript
3
star
34

storage-path-finder

Library to perform the heavy lifting when attempting to find internal / external paths for primary and secondary storage.
Java
3
star
35

multiplatform-playground

A repository to play and learn about different multi-platform technologies
TypeScript
2
star
36

dashboard-plugins

A collection of plugins for the dashboard
JavaScript
2
star
37

react-native-workshop

JavaScript
1
star
38

dreams

A REST API using Stable Diffusion for Text to Image inference
Shell
1
star
39

github-slack-action

Simple Github Action to post a message in Slack
Shell
1
star