How to run integrations test on a web project from another subproject using gradle

775 Views Asked by At

I have a gradle multi project where my war file is built in one subproject and my integrations tests are in a different subproject. I have read that gretty should be able to start a jetty instance to let me run the integrations tests during build, but I can not figure out how to "connect" the gretty integrationTestTask task to the task in my other subproject from where the actual tests will be run.

My project structure looks like this:

root/
    int-test/
        build.gradle
    web/
        build.gradle
    build.gradle
    settings.gradle

File content

root/settings.gradle:

include ':web'
include ':int-test'

root/build.gradle:

apply plugin: 'java'

root/web/build.gradle:

apply plugin: 'war'
apply from: 'https://raw.github.com/akhikhl/gretty/master/pluginScripts/gretty.plugin'

gretty {
    contextPath = '/'
    integrationTestTask = 'intTests'
}

task intTests << {
    println 'This task will run in just the right time'
}

root/int-test/build.gradle:

apply plugin: 'java'

task intTests << {
    println 'All integration testing is done in here'
}

When I run "./gradlew -q intTests", this is the output:

All integration testing is done in here
2014-12-11 15:37:02.046 INFO  - Logging initialized @1157ms
2014-12-11 15:37:02.554 INFO  - jetty-9.2.3.v20140905
2014-12-11 15:37:02.682 WARN  - ServletContainerInitializers: detected. Class hierarchy: empty
2014-12-11 15:37:03.114 INFO  - Started o.a.g.JettyWebAppContext@7da22e4a{/,file:/Users/fredrik/callista/dev/grettyfitnesse/web/build/inplaceWebapp/,AVAILABLE}
2014-12-11 15:37:03.130 INFO  - Started ServerConnector@2590ae17{HTTP/1.1}{0.0.0.0:8080}
2014-12-11 15:37:03.130 INFO  - Started @2245ms
2014-12-11 15:37:03.137 WARN  - Jetty 9.2.3.v20140905 started and listening on port 8080
2014-12-11 15:37:03.158 WARN  -  runs at:
2014-12-11 15:37:03.159 WARN  -   http://localhost:8080/
This task will run in just the right time
2014-12-11 15:37:03.221 INFO  - Stopped ServerConnector@2590ae17{HTTP/1.1}{0.0.0.0:8080}
2014-12-11 15:37:03.229 INFO  - Stopped o.a.g.JettyWebAppContext@7da22e4a{/,file:/Users/fredrik/callista/dev/grettyfitnesse/web/build/inplaceWebapp/,UNAVAILABLE}
2014-12-11 15:37:03.232 WARN  - Jetty 9.2.3.v20140905 stopped.
Server stopped.

So, the intTests task in the web project will run in the right moment but the intTests task in the int-test project will run way to early (before the web server has been started). How do I set this up so that the gretty plugin "connects" to the intTests task defined in my int-test project?

Things I have tried: * Setting "integrationTestTask = ':int-test:intTests'" hoping that it would be enough to specify in which subproject gretty should be looking for the correct task. Result - jetty is not even started. * Creating the intTests task in the root build.gradle trying to extend that task in int-test. Result - no difference. * Added a dependsOn(":int-test:intTests") to the intTests task in web project. Result - no difference

1

There are 1 best solutions below

1
On

First, check if gretty.integrationTestTask = ":int-test:intTests" works. If not, add the following to int-tests/build.gradle:

intTests {
    dependsOn(":web:taskThatStartsTheWebServer")
    finalizedBy(":web:taskThatStopsTheWebServer")
}

(You can find the task names in the Gretty docs or the output of gradle tasks.)

Note that it's task foo { dependsOn "bar" }, not task foo << { dependsOn "bar" }. Recent Gradle versions will detect this mistake and fail the build.