LoggingTestRule.java

1
package fr.sii.ogham.testing.extension.junit;
2
3
import fr.sii.ogham.testing.extension.common.Printer;
4
import fr.sii.ogham.testing.extension.common.TestInformationLogger;
5
import org.junit.rules.TestWatcher;
6
import org.junit.runner.Description;
7
8
/**
9
 * Write information about test. This is useful when there are many tests:
10
 * <ul>
11
 * <li>To quickly find the logs for the test</li>
12
 * <li>To quickly know if the test has failed or succeeded</li>
13
 * <li>To quickly identify the test failure</li>
14
 * <li>To quickly find failed tests</li>
15
 * </ul>
16
 * 
17
 * @author Aurélien Baudet
18
 *
19
 */
20
public class LoggingTestRule extends TestWatcher {
21
	private static final String SEPARATOR = ".";
22
23
	private final TestInformationLogger logger;
24
25
	/**
26
	 * Initializes with 100 characters per line, slf4j marker and "test-info"
27
	 * marker.
28
	 * 
29
	 */
30
	public LoggingTestRule() {
31
		super();
32
		this.logger = new TestInformationLogger();
33
	}
34
35
	/**
36
	 * Initializes with the provided max line length.
37
	 * 
38
	 * Uses Slf4j logger and default marker ("test-info").
39
	 * 
40
	 * @param maxLength
41
	 *            the length of each line
42
	 */
43
	public LoggingTestRule(int maxLength) {
44
		super();
45
		this.logger = new TestInformationLogger(maxLength);
46
	}
47
48
	/**
49
	 * Initializes with the provided max line length and marker.
50
	 * 
51
	 * Uses Slf4j logger.
52
	 * 
53
	 * @param maxLength
54
	 *            the length of each line
55
	 * @param marker
56
	 *            the marker for logs
57
	 */
58
	public LoggingTestRule(int maxLength, String marker) {
59
		super();
60
		this.logger = new TestInformationLogger(maxLength, marker);
61
	}
62
63
	/**
64
	 * 
65
	 * @param maxLength
66
	 *            the length of each line
67
	 * @param marker
68
	 *            the marker for logs
69
	 * @param logger
70
	 *            the logger
71
	 */
72
	public LoggingTestRule(int maxLength, String marker, Printer logger) {
73
		super();
74
		this.logger = new TestInformationLogger(maxLength, marker, logger);
75
	}
76
77
	@Override
78
	protected void starting(Description description) {
79 1 1. starting : removed call to fr/sii/ogham/testing/extension/common/TestInformationLogger::writeStart → NO_COVERAGE
		logger.writeStart(getTestName(description));
80
	}
81
82
	@Override
83
	protected void succeeded(Description description) {
84 1 1. succeeded : removed call to fr/sii/ogham/testing/extension/common/TestInformationLogger::writeSuccess → NO_COVERAGE
		logger.writeSuccess(getTestName(description));
85
	}
86
87
	@Override
88
	protected void failed(Throwable e, Description description) {
89 1 1. failed : removed call to fr/sii/ogham/testing/extension/common/TestInformationLogger::writeFailure → NO_COVERAGE
		logger.writeFailure(getTestName(description), e);
90
	}
91
92
	private static String getTestName(Description description) {
93 1 1. getTestName : replaced return value with "" for fr/sii/ogham/testing/extension/junit/LoggingTestRule::getTestName → NO_COVERAGE
		return description.getTestClass().getSimpleName() + SEPARATOR + description.getMethodName();
94
	}
95
96
}

Mutations

79

1.1
Location : starting
Killed by :
removed call to fr/sii/ogham/testing/extension/common/TestInformationLogger::writeStart → NO_COVERAGE

84

1.1
Location : succeeded
Killed by :
removed call to fr/sii/ogham/testing/extension/common/TestInformationLogger::writeSuccess → NO_COVERAGE

89

1.1
Location : failed
Killed by :
removed call to fr/sii/ogham/testing/extension/common/TestInformationLogger::writeFailure → NO_COVERAGE

93

1.1
Location : getTestName
Killed by :
replaced return value with "" for fr/sii/ogham/testing/extension/junit/LoggingTestRule::getTestName → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.13.1