Giter VIP home page Giter VIP logo

mockstar's Introduction

mockstar

Demo project for using MockWebServer for unit tests. This project also hints on mocking out views while testing using Mockito and focuses on the usage of MockWebServer for writing tests.

Using MockWebServer for writing unit tests.

Most of the demos out there make use of MockWebServer for writing androidTests and adding custom JUnitTestRunners and are more focused on integration testing. Nowadays, MVP architecture is getting adopted by many android developers and we like our logic layer to be tested properly. MVP enables proper testing of the logic layer via unit tests and separates it from the pains of testing the android UI. While testing, we should not hit the actual web server. If we hit actual server while testing, then the tests become flaky as they depend upon the actual network availability. This project shows how we can write unit tests for our Presenters / Models easily. It also shows how we can test certain error conditions properly with the use of Mockito and MockWebServer which becomes as easy as just hitting the actual remote server.

Project implements the following :

Implementation

This project has a separate module called mocks. Our android application module app has a testCompile dependency on the mocks module. Also, created a LocalResponseDispatcher which takes care of the local API needs.

We use MockWebserver to test the API calls in our ModelRepository (PokemonDataSource) and we use Mockitoto test our Presenter (MainPresenterImpl) by mocking out the view. We have also written some demo tests using MockWebServer just to show how same thing can be achieved using MockWebServer also.

Model - PokemonDataSource -> PokemonDataSourceTest (uses MockWebServer) Presenter - MainPresenterImpl -> MainPresenterImplTest (uses MockWebServer) -> MainPresenterImplMockTest (uses Mockito)

To run tests : ./gradlew clean test

To-Do

  • More Documentation.

mockstar's People

Contributors

ragdroid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  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.