【问题标题】:How to redirect log messages to test reports in Grails 2.4.x+?如何将日志消息重定向到 Grails 2.4.x+ 中的测试报告?
【发布时间】:2015-04-05 21:32:28
【问题描述】:

我最近将 Grails 2.2 项目更新为 2.4.4,我发现在运行“grails test-app”时,所有日志消息(信息、调试、错误等)现在都输出到控制台反对生成的测试报告。

以前所有的日志输出都会附加到测试报告的正文中,我只会在控制台中收到测试结果。现在默认行为是将日志消息打印到控制台中,使得在运行数百个测试时难以解析输出。

| Compiling 1 source files....
| Running 2 unit tests... 1 of 2
2015-02-05 12:16:53,965 [main] INFO  testapp.HelloController  - Hello World Log
| Completed 1 unit test, 0 failed in 0m 5s
| Tests PASSED - view reports in /Users/pk/workspace/testapp/target/test-reports

我已经确认这是 Grails 2.4.4 的默认行为(并且可能在此之前的某个时间)。有趣的是,通过“println”命令直接打印到标准输出的消息出现在日志文件中。

有谁知道如何更改此行为以将所有日志输出打印到测试报告而不是控制台?

【问题讨论】:

  • 我也有同样的问题。你找到解决办法了吗?
  • 你能给我们看看你的grails-app/conf/Config.groovy文件吗?
  • 可能是 Gradle 的事情。检查添加testLogging.showStandardStreams = false是否可以解决问题

标签: grails


【解决方案1】:

将 -echoOut 开关添加到 grails test-app,https://grails.org/wiki/1.2%20Release%20Notes

grails test-app -echoOut

test-app 上还有许多其他有用的开关,包括:

回显 System.err 消息:

grails test-app -echoErr

在运行测试之前强制清理(不执行 grails clean && grails test-app):

grails test-app -clean

只运行单元测试:

grails test-app unit:

只运行集成测试:

grails test-app integration:

在特定环境中运行:

grails -Dgrails.env=production test-app

只为特定的测试类(如 com.foo.MyControllerTests)运行测试,确保去掉“Tests”后缀

grails test-app com.foo.MyController

仅重新运行上次运行测试时失败的测试

grails test-app to output to console

【讨论】:

  • 不幸的是,这不会改变行为,-echoOut 标志将日志输出发送到标准输出,但不发送到测试报告。我正在寻找的是将日志消息记录到测试报告而不是标准输出,这是 2.2 及更低版本中的默认行为。
猜你喜欢
  • 1970-01-01
  • 2019-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-05-31
  • 1970-01-01
  • 2011-05-06
  • 2019-08-17
相关资源
最近更新 更多