GithubHelp home page GithubHelp logo

androidunittestexample's Introduction

This is an example testing in Android application

A collection of different frameworks and techniques for testing.

  1. JUnit is the most popular and widely-used unit testing framework for Java. The latest version of this framework, JUnit 4, allows you to write tests in a cleaner and more flexible way than its predecessor versions.
  2. Mockito is a mocking framework that tastes really good. It lets you write beautiful tests with a clean & simple API. Mockito doesn’t give you hangover because the tests are very readable and they produce clean verification errors. Read more about features & motivations.
  3. Jacoco is a gradle plugin that generates Jacoco reports from a Gradle Project. Android Application, Android Library and Java Plugins are supported by this plugin. When this plugin is applied it goes over every subproject and creates the corresponding Jacoco tasks.
  4. Espresso is targeted at developers, who believe that automated testing is an integral part of the development lifecycle. While it can be used for black-box testing, Espresso’s full power is unlocked by those who are familiar with the codebase under test.
  5. Spoon is a gradle plugin allows you to distribute instrumentation tests to all your Androids.
  6. Spoon Gradle Plugin is a gradle plugin for Spoon. Allows you to run spoon with almost no effort under new Android build system.

=========================================== In top-level build.gradle file of project, you need to put class path as below:

repositories {
        jcenter()
        mavenCentral()
        ...
    }
dependencies {
        ...
        classpath 'com.stanfy.spoon:spoon-gradle-plugin:1.2.2'
        classpath 'com.vanniktech:gradle-android-junit-jacoco-plugin:0.5.0'
        ...
    }

=========================================== In your app's top-level build.gradle file, you need to specify these libraries as dependencies:

    ...
    // Allows you to run spoon with almost no effort under new Android build system.
    apply plugin: 'spoon'
    // Gradle plugin that generates Jacoco reports from a Gradle Project
    apply plugin: 'com.vanniktech.android.junit.jacoco'
    ...
dependencies {
    ...
    // Espresso testing
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })
    // Spoon testing
    androidTestCompile 'com.squareup.spoon:spoon-client:1.7.0'
    testCompile 'junit:junit:4.12'
    ...
}

This section is optional

spoon {
    // for debug output
    debug = true

    // To run a single test class
    className = 'com.bonnguyen.tax.test.van.VanInstrumentedTest'

    // To run a single method in TestCase
    methodName = 'testCalculatorTax'

    // To execute the tests device by device */
    sequential = true

    // To grant permissions to Android M >= devices */
    grantAllPermissions = true
}

And

junitJacoco {
    jacocoVersion = '0.7.2.201409121644' // type String
    ignoreProjects = [] // type String array
    excludes // type String List
}

Run Local Unit Tests

  1. Using IDE, plz read more details
  2. Or open terminal on Mac OSX and run command:
  ./gradlew test

With jacoco plugin, you can also to display test summary:

  ./gradlew testDebugUnitTest

And result after run plugin

Run Instrumented Unit Tests

  1. Using IDE, plz read more details
  2. Or open terminal on Mac OSX and run command:
  ./gradlew spoon

Then display result

Bugs, Suggestions, Ideas

Any ideas/bugs/etc, as well as pull requests, are welcome in the issues section.

DEVELOP BY

Bon Nguyen - [email protected]

androidunittestexample's People

Contributors

bonnguyen avatar

Watchers

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