Grails grails test-app 与 grails test-app -integration 的区别

发布于 2024-11-08 05:48:39 字数 145 浏览 0 评论 0原文

通过 grails test-app 与 grails test-app -integration 运行 grails 测试的集成阶段有什么区别

我有一组测试将在一个测试下通过,但在另一个测试下则不会通过,但我似乎找不到什么不同在集成阶段根据两种方式来调用它。

What is the difference during the integration phase of running grails tests via grails test-app vs grails test-app -integration

I have a set of tests that will pass under one but not the other but I can't seem to find what is different in the integration phase based on the two ways to call it.

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

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

发布评论

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

评论(2

允世 2024-11-15 05:48:40

grails 中的单元测试无需设置环境即可运行。没有数据库;对象和 gorm 被模拟,您需要执行特定的操作来设置域对象以进行测试。而且您无法执行诸如测试基于 hql 的查询之类的操作(我认为该功能可能会出现在较新版本的 grails 中)

集成测试完全不同。您的引导代码将运行,所有数据库调用都会转到实际运行的数据库(如果您希望它有所不同,您可以在数据源中进行配置)。如果您从集成测试中调用服务方法,它将转到数据库,其中包含事务和其他所有内容。此外,Spring bean 自动装配/依赖注入步骤已运行,因此您的所有服务均已完全连接并准备就绪。

这是一个大概的轮廓,没有看到测试和失败,很难说哪里出了问题。

unit tests in grails run without the environment being set up. There is no database; objects and the gorm are mocked, and you need to do specific things to set up the domain objects for testing. And you can't do things like test hql based queries (I think that feature might be coming in newer versions of grails)

Integration tests are completely different. You bootstrap code is run, and all db calls go to an actual running database (which you can configure in datasources if you want it to be different). If you call a service method from an integration test, it will go to the db, with transactions and everything else. Also, The Spring bean autowiring/dependency injection step is run, so all your services are fully wired up and ready to go.

Thats a general outline, without seeing the tests and the failures, its hard to say whats wrong.

_蜘蛛 2024-11-15 05:48:40

我也遇到过类似的问题。
我不知道为什么,但集成测试的顺序是不同的。
这会导致安装/拆卸期间出现错误。基本上,一次tearDown 存在一些问题,并且没有删除setUp 中创建的所有对象。这会导致接下来的测试出错。

值得检查。

I've had a similar problem.
I'm not sure why, but the order of integration tests was different.
This lead to an error during setUp/tearDown. Basically one tearDown had some issues and didn't remove all objects which were created in setUp. This lead to an error in the next test.

Worth checking.

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