Package org.sonar.api.testfixtures.log
Class LogTesterJUnit5
- java.lang.Object
-
- org.sonar.api.testfixtures.log.LogTesterJUnit5
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension
public class LogTesterJUnit5 extends java.lang.Object implements org.junit.jupiter.api.extension.BeforeEachCallback, org.junit.jupiter.api.extension.AfterEachCallbackThis JUnit 5 extension allows to configure and access logs in tests. By default, INFO level is enabled.
Warning - not compatible with parallel execution of tests in the same JVM fork.
Example:public class MyClass { private final Logger logger = Loggers.get("logger_name"); public void doSomething() { logger.info("foo"); } } class MyClassTests { @org.junit.jupiter.api.extension.RegisterExtension LogTesterJUnit5 logTester = new LogTesterJUnit5(); @org.junit.jupiter.api.Test public void test_log() { new MyClass().doSomething(); assertThat(logTester.logs()).containsOnly("foo"); } }- Since:
- 8.1
-
-
Constructor Summary
Constructors Constructor Description LogTesterJUnit5()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voidafter()voidafterEach(org.junit.jupiter.api.extension.ExtensionContext context)protected voidbefore()voidbeforeEach(org.junit.jupiter.api.extension.ExtensionContext context)Gclear()java.util.List<LogAndArguments>getLogs()Logs with arguments in chronological order (item at index 0 is the oldest one)java.util.List<LogAndArguments>getLogs(org.slf4j.event.Level level)Logs with arguments in chronological order (item at index 0 is the oldest one) for a given leveljava.util.List<LogAndArguments>getLogs(org.sonar.api.utils.log.LoggerLevel sonarLevel)Deprecated.usegetLogs(Level)java.util.List<java.lang.String>logs()Logs in chronological order (item at index 0 is the oldest one)java.util.List<java.lang.String>logs(org.slf4j.event.Level level)Logs in chronological order (item at index 0 is the oldest one) for a given leveljava.util.List<java.lang.String>logs(org.sonar.api.utils.log.LoggerLevel sonarLevel)Deprecated.uselogs(Level)GsetLevel(org.slf4j.event.Level level)Change log level.GsetLevel(org.sonar.api.utils.log.LoggerLevel sonarLevel)Deprecated.usesetLevel(Level)
-
-
-
Method Detail
-
beforeEach
public void beforeEach(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception- Specified by:
beforeEachin interfaceorg.junit.jupiter.api.extension.BeforeEachCallback- Throws:
java.lang.Exception
-
afterEach
public void afterEach(org.junit.jupiter.api.extension.ExtensionContext context) throws java.lang.Exception- Specified by:
afterEachin interfaceorg.junit.jupiter.api.extension.AfterEachCallback- Throws:
java.lang.Exception
-
before
protected void before()
-
after
protected void after()
-
setLevel
public G setLevel(org.slf4j.event.Level level)
Change log level. By default, INFO logs are enabled when LogTester is started.
-
setLevel
@Deprecated(since="9.15") public G setLevel(org.sonar.api.utils.log.LoggerLevel sonarLevel)
Deprecated.usesetLevel(Level)
-
logs
public java.util.List<java.lang.String> logs()
Logs in chronological order (item at index 0 is the oldest one)
-
logs
public java.util.List<java.lang.String> logs(org.slf4j.event.Level level)
Logs in chronological order (item at index 0 is the oldest one) for a given level
-
logs
@Deprecated(since="9.15") public java.util.List<java.lang.String> logs(org.sonar.api.utils.log.LoggerLevel sonarLevel)
Deprecated.uselogs(Level)
-
getLogs
public java.util.List<LogAndArguments> getLogs()
Logs with arguments in chronological order (item at index 0 is the oldest one)
-
getLogs
public java.util.List<LogAndArguments> getLogs(org.slf4j.event.Level level)
Logs with arguments in chronological order (item at index 0 is the oldest one) for a given level
-
getLogs
@Deprecated(since="9.15") public java.util.List<LogAndArguments> getLogs(org.sonar.api.utils.log.LoggerLevel sonarLevel)
Deprecated.usegetLogs(Level)
-
clear
public G clear()
-
-