log-tracker

A junit 5 stub to help unit test log events and statements

License

License

Categories

Categories

Logging Application Layer Libs
GroupId

GroupId

com.callibrity.logging
ArtifactId

ArtifactId

log-tracker
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

log-tracker
A junit 5 stub to help unit test log events and statements
Project URL

Project URL

https://github.com/mwehby/junit5-log-test-stub
Source Code Management

Source Code Management

https://github.com/mwehby/junit5-log-test-stub

Download log-tracker

How to add to project

<!-- https://jarcasting.com/artifacts/com.callibrity.logging/log-tracker/ -->
<dependency>
    <groupId>com.callibrity.logging</groupId>
    <artifactId>log-tracker</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/com.callibrity.logging/log-tracker/
implementation 'com.callibrity.logging:log-tracker:1.0.1'
// https://jarcasting.com/artifacts/com.callibrity.logging/log-tracker/
implementation ("com.callibrity.logging:log-tracker:1.0.1")
'com.callibrity.logging:log-tracker:jar:1.0.1'
<dependency org="com.callibrity.logging" name="log-tracker" rev="1.0.1">
  <artifact name="log-tracker" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.callibrity.logging', module='log-tracker', version='1.0.1')
)
libraryDependencies += "com.callibrity.logging" % "log-tracker" % "1.0.1"
[com.callibrity.logging/log-tracker "1.0.1"]

Dependencies

compile (4)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.25
ch.qos.logback : logback-classic jar 1.2.3
ch.qos.logback : logback-core jar 1.2.3
org.junit.jupiter : junit-jupiter-api jar 5.2.0

test (1)

Group / Artifact Type Version
org.junit.jupiter : junit-jupiter-engine jar 5.2.0

Project Modules

There are no modules declared in this project.

junit5-log-test-stub

A junit 5 stub to help unit test log events and statements

See the following blog post for more information: https://www.callibrity.com/blog/how-to-unit-test-log-statements-with-junit5

The jar file can be pulled in and used via Maven Central Repository.

<dependency>
  <groupId>com.callibrity.logging</groupId>
  <artifactId>log-tracker</artifactId>
  <version>1.0.1</version>
</dependency>

Quick Summary CUT ( Class Under Test ) . In order to illustrate how to use the new JUnit 5 Extension model to unit test logging statements, let’s pretend we have the follow CUT.

public class CUT {

Logger logger = LoggerFactory.getLogger(CUT.class);

public void doNothingButLog() {
	logger.debug("Inside CUT.doNothingButLog");
}

public void doNothingButLogTwo() {
	logger.info("Start CUT.doNothingBugLogTwo");
	
	logger.info("End CUT.doNothingBugLogTwo");
}

}

Use the LogTrackerStub, which is a JUnit 5 Extension enabled class. It is used as follows:

public class CUTTest {

@RegisterExtension
LogTrackerStub logTrackerStub = LogTrackerStub.create().recordForLevel(LogTracker.LogLevel.INFO)
	.recordForType(CUT.class);


@Test
public void testCUTMethodOne() {
	logTrackerStub.recordForLevel(LogTracker.LogLevel.DEBUG);
	CUT classUnderTest = new CUT();
	classUnderTest.doNothingButLog();
	
	assertTrue(logTrackerStub.contains("Inside CUT.doNothingButLog"));
	assertEquals(1, logTrackerStub.size());
}

@Test
public void testCUTMethodTwo() {
	CUT classUnderTest = new CUT();
	classUnderTest.doNothingButLogTwo();
	assertTrue(logTrackerStub.contains("Start CUT.doNothingBugLogTwo"));
	assertTrue(logTrackerStub.contains("End CUT.doNothingBugLogTwo"));
	assertEquals(2, logTrackerStub.size());
	
}

}

Versions

Version
1.0.1