RxPresso


Source link: https://github.com/novoda/rxpresso

RxPresso

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

Resources

GeoFirebase is a libray to simplify the Firebase Database queries based on geolocations proximity. It will return every node in a given radius for a set of cordinates.

Command line tool to access Android Demo Ui

This tools has 2 modes:

  • Standart mode, application will evaluate all arguments, apply them and exit
  • Live mode, application starts to listen for supplied arguments and apply them. This mode helps to tweak options and receive fast feedback.

A library that converts Time to its equivalent basic local languages starting with three basic Nigeria languages (Yoruba, Hausa and Igbo) with others in pipeline.

CameraView is a well documented, high-level library that makes capturing pictures and videos easy, addressing most of the common issues and needs.

Supports gestures (tap-to-focus, pinch-to-zoom, ...), grid drawing, system permissions handling, smart sizing, metadata support and much more.

Small & simple library to create a link url, mail, mention and tag in TextView.

A custom imageView which implements shared element transition pattern on your desired image.
Using TransitionalImageView instead of android.ImageView you can click on any image to animate it to full screen mode.

Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes