运行集成测试时如何将 Grails 作为 Web 应用程序启动

发布于 2024-09-19 12:32:21 字数 1242 浏览 4 评论 0原文

我正在尝试使用发出 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 在执行集成测试时打开端口?

I'm trying to test my grails app using integration test that makes http requests. Actually it's a selenium/tellurium test, but it doesn't matter. But as i see when i running grails tests it doesn't starts web container, the same time i see many examples in blog articles that people tests grails app using selenium and other test tools that requires http access.

I've create an empty grails app:

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

thats ok.

and now add an integration test that tries to connect to grails test/integration/ListenPortTest.groovy:

class ListenPortTest extends GroovyTestCase {
        void testPort(){
                def s = new Socket("localhost", 8080);
                s.close()
        }        
}

and run test again. Now we receive following exception:

Connection refused
   java.net.ConnectException: Connection refused
   ....

I've checked it also by using browser, wget and netstat, and looks like grails not started or not opened any port.

And the question:
How i can configure grails to open an port when executing integration tests?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

以为你会在 2024-09-26 12:32:21

Grails 默认支持两种类型的测试:单元测试和集成测试,以及使用插件的功能测试。单元测试和集成测试非常相似,实际上都是单元测试,不同之处在于集成测试具有初始化的 Spring 应用程序上下文、Hibernate 配置、内存数据库等。但是没有正在运行的 Web 服务器 - 您需要为此进行功能测试。

功能测试有多种选项,最流行的是 WebTest: http://grails.org/plugin/webtest< /a>,功能测试插件:http://grails.org/plugin/function-test,以及 Selenium RC 插件:http://grails.org/plugin/selenium-rc

最新的是 Geb:http://grails.org/plugin/geb 如果您正在寻找对于 Selenium 支持,这将是您最好的选择。该手册位于 http://geb.codehaus.org/,最近有一篇关于它的博客文章这里:http://blog.springsource。 com/2010/08/28/the-future-of-function-web-testing/

Grails supports two types of tests by default, unit and integration, plus functional testing using a plugin. Unit and integration tests are quite similar and are really both unit tests, except that integration tests have an initialized Spring application context, Hibernate configuration, in-memory database, etc. But no running web server - you need functional tests for that.

There are several options for functional testing, the most popular ones being WebTest: http://grails.org/plugin/webtest, the Functional Testing plugin: http://grails.org/plugin/functional-test, and the Selenium RC plugin: http://grails.org/plugin/selenium-rc.

The newest one is Geb: http://grails.org/plugin/geb and if you're looking for Selenium support it's going to be your best bet. The manual is at http://geb.codehaus.org/ and there was a recent blog post written about it here: http://blog.springsource.com/2010/08/28/the-future-of-functional-web-testing/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文