Giter Site home page Giter Site logo

android-test's Introduction

Basic sample for writing unit tests that mocks the Android framework

If you are new to unit testing on Android, try this sample first.

This project uses the Gradle build system and the Android gradle plugin support for unit testing. You can either benefit from IDEs integration such as Android studio or run the tests on the command line.

Unit tests run on a local JVM on your development machine. The Android Gradle plugin will compile your app's source code and execute it using gradle test task. Tests are executed against a modified version of android.jar where all final modifiers have been stripped off. This lets you use popular mocking libraries, like Mockito.

For more information see http://tools.android.com/tech-docs/unit-testing-support

Setup the project in Android studio and run tests.

  1. Download the project code, preferably using git clone.
  2. In Android Studio, select File | Open... and point to the ./build.gradle file.
  3. Make sure you select "Unit Tests" as the test artifact in the "Build Variants" panel in Android Studio.
  4. Check out the relevant code:
    • The application code is located in src/main/java
    • Unit Tests are in src/test/java
  5. Create a test configuration with the JUnit4 runner: org.junit.runners.JUnit4
    • Open Run menu | Edit Configurations
    • Add a new JUnit configuration
    • Choose module app
    • Select the class to run by using the ... button
  6. Run the newly created configuration

The unit test will be ran automatically.

Use Gradle on the command line.

After downloading the projects code using git clone you'll be able to run the unit tests using the command line:

./gradlew test

If all the unit tests have been successful you will get a BUILD SUCCESSFUL message.

See the report.

A report in HTML format is generated in app/build/reports/tests

android-test's People

Contributors

utsavtulsyan avatar deepforu47 avatar

Watchers

James Cloos 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.