coo*_*avi 3 java logging spring-test wiremock spring-cloud-contract
根据官方文档How to Debug,我需要将以下内容添加到属性文件中以启用日志记录
logging.level.org.apache.http.wire=DEBUG
logging.level.com.github.tomakehurst.wiremock=DEBUG
Run Code Online (Sandbox Code Playgroud)
但是,当请求发送到wiremock服务器时,我在控制台上看不到任何可见的日志。我500 Internal Server Error只得到特定的平台。因此,为了排除故障,我尝试在请求到达wiremock服务器时拦截活动。
在我的 pom 文件中
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-contract-stub-runner</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webflux</artifactId>
<scope>test</scope>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我还尝试添加logback-test.xml包含以下内容的文件。但是,这也没有记录任何内容。
<logger name="com.github.tomakehurst.wiremock" level="DEBUG"/>
<logger name="wiremock.org" level="DEBUG"/>
<logger name="WireMock" level="DEBUG"/>
<logger name="/" level="DEBUG"/>
Run Code Online (Sandbox Code Playgroud)
我的测试班
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT,
classes = MyApplication.class)
@AutoConfigureMockMvc
@TestPropertySource(
locations = "/application-integration-test.properties"
)
@AutoConfigureWireMock(port = 0)
@AutoConfigureWebTestClient(timeout = "100000")
public class MyApplicationTest {
private WebTestClient client;
@LocalServerPort
private int port;
@Before
public void setUp() throws Exception {
client = WebTestClient.bindToServer().baseUrl("http://localhost:" + port).build();
}
/// Test code
}
Run Code Online (Sandbox Code Playgroud)
有人建议缺少什么吗?
如果您通过 Spring 注解使用 WireMock @AutoConfigureWireMock,在测试控制台输出中查看 WireMock(详细)日志的最佳方法应该是在您的测试类中添加此 bean:
@TestConfiguration
static class WireMockTestConfiguration {
@Bean
WireMockConfigurationCustomizer optionsCustomizer() {
return config -> config.notifier(new ConsoleNotifier(true));
}
}
Run Code Online (Sandbox Code Playgroud)
您可以使用@Import添加WireMockTestConfiguration到 Spring 上下文。