|
5 | 5 | import io.qameta.allure.Epic; |
6 | 6 | import io.qameta.allure.Feature; |
7 | 7 | import io.qameta.allure.Owner; |
8 | | -import io.qameta.allure.util.ResultsUtils; |
9 | 8 | import io.qameta.allure.Severity; |
10 | 9 | import io.qameta.allure.Story; |
11 | 10 | import io.qameta.allure.model.Label; |
12 | 11 | import io.qameta.allure.model.Link; |
13 | 12 | import io.qameta.allure.model.Status; |
| 13 | +import io.qameta.allure.model.StatusDetails; |
14 | 14 | import io.qameta.allure.model.TestResult; |
| 15 | +import io.qameta.allure.util.ResultsUtils; |
| 16 | +import org.junit.Ignore; |
15 | 17 | import org.junit.runner.Description; |
16 | 18 | import org.junit.runner.Result; |
17 | 19 | import org.junit.runner.notification.Failure; |
|
43 | 45 | * Allure Junit4 listener. |
44 | 46 | */ |
45 | 47 | @RunListener.ThreadSafe |
46 | | -@SuppressWarnings("PMD.ExcessiveImports") |
| 48 | +@SuppressWarnings({"PMD.ExcessiveImports", "PMD.CouplingBetweenObjects"}) |
47 | 49 | public class AllureJunit4 extends RunListener { |
48 | 50 |
|
49 | 51 | public static final String MD_5 = "md5"; |
@@ -78,25 +80,7 @@ public void testRunFinished(final Result result) throws Exception { |
78 | 80 | @Override |
79 | 81 | public void testStarted(final Description description) throws Exception { |
80 | 82 | final String uuid = testCases.get(); |
81 | | - final String id = getHistoryId(description); |
82 | | - |
83 | | - final TestResult result = new TestResult() |
84 | | - .withUuid(uuid) |
85 | | - .withHistoryId(id) |
86 | | - .withName(description.getMethodName()) |
87 | | - .withFullName(String.format("%s.%s", description.getClassName(), description.getMethodName())) |
88 | | - .withLinks(getLinks(description)) |
89 | | - .withLabels( |
90 | | - new Label().withName("package").withValue(getPackage(description.getTestClass())), |
91 | | - new Label().withName("testClass").withValue(description.getClassName()), |
92 | | - new Label().withName("testMethod").withValue(description.getMethodName()), |
93 | | - |
94 | | - new Label().withName("suite").withValue(description.getClassName()), |
95 | | - |
96 | | - new Label().withName("host").withValue(getHostName()), |
97 | | - new Label().withName("thread").withValue(getThreadName()) |
98 | | - ); |
99 | | - |
| 83 | + final TestResult result = createTestResult(uuid, description); |
100 | 84 | result.getLabels().addAll(getLabels(description)); |
101 | 85 | getDisplayName(description).ifPresent(result::setName); |
102 | 86 | getLifecycle().scheduleTestCase(result); |
@@ -128,12 +112,28 @@ public void testFailure(final Failure failure) throws Exception { |
128 | 112 |
|
129 | 113 | @Override |
130 | 114 | public void testAssumptionFailure(final Failure failure) { |
131 | | - //not implemented |
| 115 | + final String uuid = testCases.get(); |
| 116 | + getLifecycle().updateTestCase(uuid, testResult -> |
| 117 | + testResult.withStatus(Status.SKIPPED) |
| 118 | + .withStatusDetails(getStatusDetails(failure.getException()).orElse(null)) |
| 119 | + ); |
132 | 120 | } |
133 | 121 |
|
134 | 122 | @Override |
135 | 123 | public void testIgnored(final Description description) throws Exception { |
136 | | - //not implemented |
| 124 | + final String uuid = testCases.get(); |
| 125 | + testCases.remove(); |
| 126 | + |
| 127 | + final TestResult result = createTestResult(uuid, description); |
| 128 | + result.getLabels().addAll(getLabels(description)); |
| 129 | + getDisplayName(description).ifPresent(result::setName); |
| 130 | + result.setStatus(Status.SKIPPED); |
| 131 | + result.setStatusDetails(getIgnoredMessage(description)); |
| 132 | + result.setStart(System.currentTimeMillis()); |
| 133 | + |
| 134 | + getLifecycle().scheduleTestCase(result); |
| 135 | + getLifecycle().stopTestCase(uuid); |
| 136 | + getLifecycle().writeTestCase(uuid); |
137 | 137 | } |
138 | 138 |
|
139 | 139 | private Optional<String> getDisplayName(final Description result) { |
@@ -235,4 +235,29 @@ private MessageDigest getMessageDigest() { |
235 | 235 | private String getPackage(final Class<?> testClass) { |
236 | 236 | return testClass.getPackage().getName(); |
237 | 237 | } |
| 238 | + |
| 239 | + private StatusDetails getIgnoredMessage(final Description description) { |
| 240 | + final Ignore ignore = description.getAnnotation(Ignore.class); |
| 241 | + final String message = Objects.nonNull(ignore) && !ignore.value().isEmpty() |
| 242 | + ? ignore.value() : "Test ignored (without reason)!"; |
| 243 | + return new StatusDetails().withMessage(message); |
| 244 | + } |
| 245 | + |
| 246 | + private TestResult createTestResult(final String uuid, final Description description) { |
| 247 | + return new TestResult() |
| 248 | + .withUuid(uuid) |
| 249 | + .withHistoryId(getHistoryId(description)) |
| 250 | + .withName(description.getMethodName()) |
| 251 | + .withFullName(String.format("%s.%s", description.getClassName(), description.getMethodName())) |
| 252 | + .withLinks(getLinks(description)) |
| 253 | + .withLabels( |
| 254 | + new Label().withName("package").withValue(getPackage(description.getTestClass())), |
| 255 | + new Label().withName("testClass").withValue(description.getClassName()), |
| 256 | + new Label().withName("testMethod").withValue(description.getMethodName()), |
| 257 | + new Label().withName("suite").withValue(description.getClassName()), |
| 258 | + new Label().withName("host").withValue(getHostName()), |
| 259 | + new Label().withName("thread").withValue(getThreadName()) |
| 260 | + ); |
| 261 | + } |
| 262 | + |
238 | 263 | } |
0 commit comments