【发布时间】:2010-09-15 01:21:42
【问题描述】:
我正在尝试使用发出 http 请求的集成测试来测试我的 grails 应用程序。实际上这是一个硒/碲测试,但这没关系。但正如我所见,当我运行 grails 测试时,它不会启动 Web 容器,同时我在博客文章中看到许多示例,人们使用 selenium 和其他需要 http 访问的测试工具来测试 grails 应用程序。
我创建了一个空的 grails 应用程序:
mvn org.apache.maven.plugins:maven-archetype-plugin:2.0-alpha-4:generate -DarchetypeGroupId=org.grails -DarchetypeArtifactId=grails-maven-archetype -DarchetypeVersion=1.3.4 -DgroupId=example -DartifactId=testportapp
cd testportapp/
mvn initialize
mvn grails:test-app
Tests PASSED - view reports in target/test-reports
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
没关系。
现在添加一个尝试连接到 grails test/integration/ListenPortTest.groovy 的集成测试:
class ListenPortTest extends GroovyTestCase {
void testPort(){
def s = new Socket("localhost", 8080);
s.close()
}
}
然后再次运行测试。现在我们收到以下异常:
Connection refused
java.net.ConnectException: Connection refused
....
我还使用浏览器、wget 和 netstat 进行了检查,看起来 grails 没有启动或没有打开任何端口。
还有问题: 执行集成测试时如何配置 grails 以打开端口?
【问题讨论】:
标签: java grails groovy integration-testing