简体   繁体   English

如何在grails 3中运行单个集成测试?

[英]How do I run a single integration test in grails 3?

Grails 3 (at least 3.1.10) is flaky in running only specific tests. Grails 3(至少3.1.10)在仅运行特定测试时是不稳定的。 How do I get it to run a single integration test? 如何让它运行单个集成测试?

Here is a sample command to run a single integration test 以下是运行单个集成测试的示例命令

grails test-app *LoginFunctional* -integration

If you put -integration flag before pattern, the test-app command will ignore the pattern and execute all integration tests. 如果在模式之前放置-integration标志,则test-app命令将忽略该模式并执行所有集成测试。

The official command line syntax is grails test-app , optionally followed by a pattern to match the full namespaced class name of what you want to test such as org.myorg.ClassToTest or org.**.* , and -unit or -integration to select a specific phase. 官方命令行语法是grails test-app ,可选地后跟一个模式以匹配您要测试的完整命名空间类名,例如org.myorg.ClassToTestorg.**.* ,以及-unit-integration选择一个特定的阶段。 See the docs . 查看文档

There are a number of quirks in Grails 3.1.10, though. 不过,Grails 3.1.10中有许多怪癖。

1) grails test-app won't always run the tests, probably a bug in the dependency management. 1) grails test-app不会总是运行测试,可能是依赖管理中的一个错误。 If you first remove the test report at build/reports/tests/index.html grails will see that it actually needs to do something to generate a new report. 如果您首先在build/reports/tests/index.html删除测试报告,grails将看到它实际上需要做一些事情来生成新报告。

2) Sometimes things just go randomly weird. 2)有时事情会随机变得奇怪。 If so, do grails clean; grails test clean 如果是这样,那就grails clean; grails test clean grails clean; grails test clean . grails clean; grails test clean (I didn't yet figure out if you really need both of them or only one of the two.) (我还没弄清楚你是否真的需要它们或只需要其中一个。)

3) The official way should work, but do (2) first if it doesn't. 3)官方方式应该有效,但如果没有,则先做(2)。 Also, if you want to run only a specific integration test you need to add -integration or you'll get an error. 此外,如果您只想运行特定的集成测试,则需要添加-integration否则您将收到错误。 I think without such a flag Grails unconditionally first tries to run unit tests and then integration tests, and if your test pattern does not match any unit tests grails will error out. 我认为没有这样的标志Grails无条件地首先尝试运行单元测试然后进行集成测试,如果你的测试模式与任何单元测试都不匹配,那么grails会出错。 Similarly if the pattern only matches unit tests add -unit or you'll get an error, though you still get the correct test report in this case. 类似地,如果模式只匹配单元测试添加-unit或者你会得到一个错误,尽管在这种情况下你仍然得到正确的测试报告。

4) There's also an alternative way, by using the -Dtest.single=<classname> flag. 4)通过使用-Dtest.single=<classname>标志,还有另一种方法。 This sets a system property that is picked up by gradle. 这将设置由gradle拾取的系统属性。 I only got it working properly if I also added a -unit flag, but I didn't investigate very deep. 如果我还添加了一个-unit标志,我只能让它正常工作,但我没有深入调查。

I usually use annotation @IgnoreRest . 我通常使用注释@IgnoreRest Remember to import spock.lang.IgnoreRest and run test on specified class. 记得import spock.lang.IgnoreRest并在指定的类上运行test。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM