Search results
Capture and Assert Logs with JUnit 5 in Spring Boot applications
SomeJavaClassIntegrationTest.java
:
@ExtendWith({ SpringExtension.class, OutputCaptureExtension.class })
// ...
public class SomeJavaClassIntegrationTest {
// ...
@Test
public void shouldConsumeMessage(CapturedOutput output) {
// Given
// ...
// When
// ...
// Then
MatcherAssert.assertThat(output.getOut(), Matchers.containsString("Blah String"));
// Or
Awaitility.await().atMost(2, TimeUnit.SECONDS).until(() ->
output.getOut().contains("Blah String"));
}
// ...
}