[英]How to run integrations test on a web project from another subproject using gradle
I have a gradle multi project where my war file is built in one subproject and my integrations tests are in a different subproject. 我有一个gradle多项目,其中我的war文件构建在一个子项目中,而集成测试在另一个子项目中。 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. 我已经读过gretty应该能够启动码头实例,以便在构建过程中运行集成测试,但是我无法弄清楚如何将gretty integrationTestTask任务“连接”到其他子项目中的实际测试中。将运行。
My project structure looks like this: 我的项目结构如下:
root/
int-test/
build.gradle
web/
build.gradle
build.gradle
settings.gradle
root/settings.gradle: 根/ settings.gradle:
include ':web'
include ':int-test'
root/build.gradle: 根/的build.gradle:
apply plugin: 'java'
root/web/build.gradle: 根/网络/的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: 根/ INT-测试/的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: 当我运行“ ./gradlew -q intTests”时,这是输出:
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). 因此,Web项目中的intTests任务将在适当的时候运行,但是int-test项目中的intTests任务将运行得更早(在启动Web服务器之前)。 How do I set this up so that the gretty plugin "connects" to the intTests task defined in my int-test project? 我该如何设置以便gretty插件“连接”到我的int-test项目中定义的intTests任务?
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. 我尝试过的事情:*设置“ integrationTestTask =':int-test:intTests'”,希望它足以指定gretty在哪个子项目中寻找正确的任务。 Result - jetty is not even started. 结果-码头甚至没有开始。 * Creating the intTests task in the root build.gradle trying to extend that task in int-test. *在root build.gradle中创建intTests任务,尝试在int-test中扩展该任务。 Result - no difference. 结果-无差异。 * Added a dependsOn(":int-test:intTests") to the intTests task in web project. *在Web项目中的intTests任务中添加了DependOn(“:int-test:intTests”)。 Result - no difference 结果-无差异
First, check if gretty.integrationTestTask = ":int-test:intTests"
works. 首先,检查gretty.integrationTestTask = ":int-test:intTests"
有效。 If not, add the following to int-tests/build.gradle
: 如果没有,请将以下内容添加到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
.) (您可以在Gretty文档中或gradle tasks
的输出中找到任务名称。)
Note that it's task foo { dependsOn "bar" }
, not task foo << { dependsOn "bar" }
. 请注意,它是task foo { dependsOn "bar" }
,而不是task foo << { dependsOn "bar" }
。 Recent Gradle versions will detect this mistake and fail the build. 最近的Gradle版本将检测到此错误并使构建失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.