gradle-plugin-robospock is a small gradle plugin for the sole purpose of setting up robospock (gradle + spock + roboelectric) as easily as possible.
Robospock will basically let you do unit/integration testing of android specific code using the praised spock framework which uses specification driven testing and BDD (Behavior-Driven Development) using groovy.
And all of this happens using roboelectric which avoids the hassle and latency involved in doing testing on an actual android device or worse, an emulator.
Note: Since 1.0.0, the plugin requires gradle 2.2. To use the plugin you must must load it into the buildscript like so:
buildscript {
repositories {
jcenter()
}
dependencies {
classpath 'com.jakewharton.sdkmanager:gradle-plugin:0.12.+'
classpath 'se.centril.robospock:gradle-plugin-robospock:1.0.1'
}
}
Given an android project with the path :app
, and a test project with the
path :test
, we can apply the plugin on :app
with:
apply plugin: 'robospock'
robospock {
android = project( ':app' )
}
If your test project is named app-test
, i.e the same as the application or library but with the suffix -test
(to be exact, the regex: /[^a-zA-Z0-9]?test/
), and if the app is the parent of the test project or is a sibling of it, then you may simply omit specifying the robospock.android
part alltogether as it is automatically configured. Then it becomes:
apply plugin: 'robospock'
When you have done this, you can use the test
task as usual, or robospock
task if you only want to run robospock tests.
It is also possible to apply the plugin from an android project like so:
apply plugin: 'robospock'
robospock {
tester = project( ':app-test' )
}
If you have a project named test
as a child or app-test
as a child or a sibling of the android project, it will be automatically found and used. This can rid you of the need for a build.gradle
file for the tester project altogether.
The available options are:
robospock {
// Sets the android project to test, from a tester project.
android = <gradle_android_project_object>
// Sets the tester project to test with, from an android project.
tester = <gradle_tester_project_object>
// One of the build-types specified in android_project_build_type,
// default: 'debug'
buildType = '<android_project_build_type>'
// Version of robospock to use as dependency.
// default: '0.5.+'
robospockVersion = '<dependency_version>'
// Version of spock to use as dependency.
// default: '0.7-groovy-2.0'
spockVersion = '<dependency_version>'
// Version of groovy to use as dependency.
// default: '2.3.6'
groovyVersion = '<dependency_version>'
// Version of cglib to use as dependency.
// default: '3.1'
// If the dependency is unwanted, set the string to empty.
cglibVersion = '<dependency_version>'
// Version of objenesis to use as dependency.
// default: '2.1'
// If the dependency is unwanted, set the string to empty.
objenesisVersion = '<dependency_version>'
// You can provide closures that will be run
// after RoboSpockAction has finished its work.
afterConfigured { RoboSpockConfiguration c ->
// do some additional configuration.
}
// (Read Only) robospock testing task,
// can only be read from afterConfigured closures.
robospockTask
// (Read Only) The project you applied this plugin from.
perspective
}
By default, the plugin adds the much used optional spock-dependencies objenesis
and cglib
which are used for mocking, etc. You can change the version used, or disable them by setting an empty version.
- IntelliJ & Android Studio:s gradle plugin might trigger the error:
project ':x' is not an android project
. It should however work with running the tests via gradle manually. This is a bug in IntelliJ. See issue #5.
See CHANGES.md
Want to contribute? Great stuff! Please use the issue system that github provides to report bugs/issues or request an enhancement. Pull requests are also more than welcome.
gradle-plugin-robospock is licensed under Apache License 2.0, see LICENSE.md for more information.
See AUTHORS.md