forked from knastnt/JavaRush-Training-Topjava
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimingExtension.java
More file actions
36 lines (28 loc) · 1.16 KB
/
TimingExtension.java
File metadata and controls
36 lines (28 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package ru.javawebinar.topjava;
import org.junit.jupiter.api.extension.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.StopWatch;
public class TimingExtension implements
BeforeTestExecutionCallback, AfterTestExecutionCallback, BeforeAllCallback, AfterAllCallback {
private static final Logger log = LoggerFactory.getLogger("result");
private StopWatch stopWatch;
@Override
public void beforeAll(ExtensionContext extensionContext) throws Exception {
stopWatch = new StopWatch("Execution time of " + extensionContext.getRequiredTestClass().getSimpleName());
}
@Override
public void beforeTestExecution(ExtensionContext extensionContext) throws Exception {
String testName = extensionContext.getDisplayName();
log.info("\nStart " + testName);
stopWatch.start(testName);
}
@Override
public void afterTestExecution(ExtensionContext extensionContext) throws Exception {
stopWatch.stop();
}
@Override
public void afterAll(ExtensionContext extensionContext) throws Exception {
log.info('\n' + stopWatch.prettyPrint() + '\n');
}
}