我有一个用Java编写的服务器,它是我的应用程序,我想对它运行一些测试。我使用gradle来管理依赖项并构建任务和东西,所以我也想用它。我需要启动服务器,然后运行我的单元测试,它会对它发出一堆HTTP请求,然后理想情况下甚至在测试完成后关闭服务器。所以我尝试添加到我的build.gradle test.dependsOn(jettyRunWar)
,(jettyRunWar是运行服务器的东西),但我想这太简单了,因为gradle test
永远不会从jettyRunWar返回以继续测试。我可以将它连接起来,以便gradle启动服务器,然后运行测试吗?
答案 0 :(得分:1)
呀!雅得加
jettyRunWar {
daemon = true
}
到你的build.gradle。然后,如果你想在最后关闭服务器,你也必须投入:
stopPort = 1234
stopKey = 'stopKey'
// gradle is luser. Full story (and code copied from): https://issues.gradle.org/browse/GRADLE-2263
import org.gradle.api.plugins.jetty.internal.Monitor
[jettyRun, jettyRunWar]*.doLast {
/**
* THIS IS A WORKAROUND! THE CURRENT VERSION OF THIS TASK DOESN'T START A WATCHER IN DAEMON MODE
*
* If starting the monitor fails, it may be because the jetty task was updated to fix this issue
* When that happens, we shouldn't need the custom task any more
*
* Copied From: AbstractJettyRunTask
*/
if (getStopPort() != null && getStopPort() > 0 && getStopKey() != null) {
Monitor monitor = new Monitor(getStopPort(), getStopKey(), server.getProxiedObject());
monitor.start();
}
}
确保包含关于" gradle是luser"。
的评论