Where could I find some resources for writing unit/integration tests for Gradle plugins I’m developing? Looking at all of the 3rd party plugins, it seems almost no one has any tests. It also seems like the handy test fixtures are kept internal to gradle. Please advise.
Hi Eric,
There’s currently no way to practically integration test custom build logic. Fixing this is on our roadmap.
http://forums.gradle.org/gradle/topics/testing_toolkit_for_custom_build_logic
The stuff that is in the Gradle build itself won’t work outside of the Gradle build, and is not really suitable for that use anyway. What we do eventually provide will end up with a similar kind of interface but needs to be implemented very differently.
If you’re just looking to unit test, the ProjectBuilder api has some facilities that can help. Here’s an example of unit testing a plugin: https://github.com/kellyrob99/gradle-jslint-plugin/blob/master/src/test/groovy/org/kar/jslint/gradle/plugin/JSLintPluginTest.groovy
Did you get this to work with debug logging? I could not properly instantiate the logger. So change the project.logging.debug in the real class to a debug(Project project, String output) and called that to log and check if logger was not null, etc. The println is to enable debug on the test results page. Its hacky but it works until I can work out
def debug (Project project, String output) {
if (project != null && project.logger != null) {
project.logger.debug(output)
}
//Assume test env ?
if (project==null || project.logger==null) {
println output
}
}