1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package de.kaiserpfalzedv.commons.test;
19
20 import lombok.Setter;
21 import org.junit.jupiter.api.AfterEach;
22 import org.slf4j.Logger;
23 import org.slf4j.LoggerFactory;
24 import org.slf4j.MDC;
25
26 import jakarta.validation.constraints.NotNull;
27
28
29
30
31
32
33
34 @Setter
35 public class AbstractTestBase {
36 private static final String MDC_TEST_SUITE_KEY = "test-class";
37 private static final String MDC_TEST_KEY = "test";
38
39 private Logger log = LoggerFactory.getLogger("test");
40 private String testSuite = "unspecified";
41
42 public void setTestSuite(final String suite) {
43
44 testSuite = suite.replace("_Subclass", "");
45 }
46
47 protected void startTest(@NotNull final String test, Object... params) {
48 MDC.put(MDC_TEST_SUITE_KEY, testSuite);
49 MDC.put(MDC_TEST_KEY, test);
50
51 log.info("Starting test ... test='{}', params={}", test, params);
52 }
53
54 @AfterEach
55 void removeTestFromMDC() {
56 log.debug("Test finished. test='{}'", MDC.get(MDC_TEST_KEY));
57
58 MDC.remove(MDC_TEST_KEY);
59 MDC.remove(MDC_TEST_SUITE_KEY);
60 }
61 }