Git Product home page Git Product logo

mockitoexample's Introduction

MockitoExample

Sample code for the talk "Testing made sweet with a Mockito" that I gave at Droidcon Berlin 2016.

slides: https://speakerdeck.com/jeroenmols/testing-made-sweet-with-a-mockito

Interesting code parts

  • build.gradle file indicating how to configure Mockito
    • testCompile: for tests run on your computer in a JVM (src/test folder)
    • androidTestCompile: for tests run on an Android device (src/androidTest folder)
  • UserTest class demonstrating Mockito usage
    • TLDR: JVM unit tests with mockito are easy to read and write
  • UserTestAndroid class demonstrating Mockito usage on Android device
    • TLDR: Mockito can be used on Android, but need to use V1 and dexmaker
  • HandlerWrapper class indicating how to test final methods
    • TLDR: Wrap final or statics methods with a different non static/final method
  • TestUserData class indicating how to provide testing data for POJO objects
    • TLDR: Override all methods with default values instead of creating a mock and stubbing them out
  • Custom matchers classes indicating how to create your own custom Mockito matchers
    • TLDR: Implement ArgumentMacher interface and provide static methods for easy access
  • Mocking final methods How to configure Mockito 2.+ to mock final methods
    • TLDR: Recreate one file (exact content and location) and you can mock final methods in jvm tests

mockitoexample's People

Contributors

jeroenmols avatar

Watchers

 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.