从Gradle运行Groovy Spock测试时,我习惯于在JUnit的stdout选项卡中查看所有HTTP请求。大规模升级(请参阅this large commit)后,此操作将不再起作用。
因为这在调试测试失败时非常有帮助,所以我很想找回它。 Groovy Spock测试中似乎没有使用任何升级的依赖项,因此没有明显的候选对象。接下来,我搜索了很多属性,该属性会将HTTP请求再次记录到stdout,但找不到它。
有人知道吗?
谢谢!
伯特
答案 0 :(得分:0)
进一步挖掘,很明显,更改是由org.springframework.boot
从1.5.7.RELEASE
升级到2.0.4.RELEASE
引起的。在Spring Boot 1.5中,使用了LogBack,现在是JUL。
要再次打开日志记录,我在build.gradle
中设置了Java系统属性:
systemProperties = [
"java.util.logging.config.file": "<some path>/logging.properties"
]
要获得我喜欢的日志记录,请将以下内容放入logging.properties
:
handlers= java.util.logging.ConsoleHandler
java.util.logging.ConsoleHandler.level = ALL
java.util.logging.ConsoleHandler.formatter = java.util.logging.SimpleFormatter
java.util.logging.SimpleFormatter.format = %1$tH:%1$tM:%1$tS.%1$tL %4$-6s %2$s - %5$s%n
.level=FINEST
这样,Apache客户端再次记录HTTP请求:
20:16:32.050 FINE groovyx.net.http.RESTClient doRequest - POST http://localhost:8082/users/?
20:16:32.611 FINE org.apache.http.impl.conn.BasicClientConnectionManager getConnection - Get connection for route {}->http://localhost:8082
20:16:32.631 FINE org.apache.http.impl.conn.DefaultClientConnectionOperator openConnection - Connecting to localhost:8082
20:16:32.660 FINE org.apache.http.client.protocol.RequestAddCookies process - CookieSpec selected: default
这在分析测试失败时提供了很大的帮助。