A collection of different frameworks and techniques for testing.
- 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.
- 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.
- 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.
- 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.
- Spoon is a gradle plugin allows you to distribute instrumentation tests to all your Androids.
- 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
}
- Using IDE, plz read more details
- 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
- Using IDE, plz read more details
- Or open terminal on Mac OSX and run command:
./gradlew spoon
Then display result
Any ideas/bugs/etc, as well as pull requests, are welcome in the issues section.