Package de.neuland.assertj.logging
Class GenericExpectedLogging<APPENDER extends LogEventCaptureAppender>
- java.lang.Object
-
- de.neuland.assertj.logging.GenericExpectedLogging<APPENDER>
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension
public abstract class GenericExpectedLogging<APPENDER extends LogEventCaptureAppender> extends java.lang.Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallbackTheExpectedLoggingrule allows you to verify that your code logs messages in the underlying logging framework.Usage
public class SimpleLoggingTest { @Rule public ExpectedLogging logging = ExpectedLogging.forSource(LoggingSource.class); @Test public void shouldLogError() { String message = "Error Message"; new LoggingSource().doSomethingThatLogsAnError(); LoggingAssertions.assertThat(logging).hasErrorMessage(message); } }You have to add the
ExpectedLoggingrule to your test. This doesn't affect your existing tests. After executing the method that is expected to log, you can verify this with assertj assertions defined inExpectedLoggingAssert
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context)voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context)java.util.List<LogEvent>getLogEvents()
-
-
-
Method Detail
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context)
- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context)
- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback
-
getLogEvents
public java.util.List<LogEvent> getLogEvents()
-
-