gradleware/oreilly-gradle-book-examples — pull request #4 by tniedzwiedz (2014-08-02 21:08:25+00:00)
Title: The testing-geb example wouldn't run

Hello, I learned about Gradle today and I started reading your book and following the examples as I go. I've run into some trouble running the `testing-geb` example.

When I run it with `gradle test` (the way suggested in the `run-example.bsh` for the project), the build passes but no output (reports/test results, not even a `build` directory) appears in the project's directory. Furthermore, when I change the `google.story` file in an attempt to break the test, for instance:

then "we are at google", {
page.title.shouldBe "Microsoft"
}

the build still passes as if nothing happened.

Upon closer inspection, it seems that the `test` task stops prematurely because the project contains no test classes and all of the relevant code is put in `test.doLast`, which never executes.

Running the build with `-i` yields the following message

>file or directory 'C:\repos\oreilly-gradle-book-examples\testing-geb\build\classes\test', not found
Skipping task ':test' as it has no source files.

I tried passing the closure to a custom task instead of the `test.doLast`, in the following way:

task integrationTest << {
ant.taskdef(name: "easyb", classname:"org.easyb.ant.BehaviorRunnerTask", classpath: sourceSets.test.runtimeClasspath.asPath)

ant.easyb( classpath: sourceSets.test.runtimeClasspath.asPath, failureProperty:'easyb_failed' ) {
report( location:"${project.testResultsDir}/story.html", format:"html" )
behaviors( dir: "src/test/stories" ) {
include( name:"**/*.story" )
}
}

ant.fail( if:'easyb_failed', message: 'Failures in easyb stories')
}

and running the test with `gradle integrationTest`. This time, it proceeded to download the dependencies and attempted to run the scenario. Unfortunately, it failed again and reported missing JavaScript files that it apparently expected to be present in the `build\test-results` directory.

Again, the `build` directory was not created. This is because obviously the new task does not come with all the functionality provided by `test`.

I managed to run the test properly by adding a dummy test class to the project. The story itself fails because the test does not take into account the localized versions of google search and the titles don't match the ones I see in the browser. But don't think it's an issue for a simple example like this. What's important is that the story was actually executed and the reports were generated successfully.

I thought I'd share the solution, however naive. If there's a cleaner way to make the test run properly, please let me know. Perhaps there's a way to run the `test` task despite having no test classes available.