Skip to content

Commit ec171cf

Browse files
gladnikbaev
authored andcommitted
junit4 - fix npe with ignore annotation on classes (via #119)
1 parent 73dceba commit ec171cf

File tree

3 files changed

+41
-10
lines changed

3 files changed

+41
-10
lines changed

allure-junit4/src/main/java/io/qameta/allure/junit4/AllureJunit4.java

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,6 @@ public void testRunFinished(final Result result) throws Exception {
8181
public void testStarted(final Description description) throws Exception {
8282
final String uuid = testCases.get();
8383
final TestResult result = createTestResult(uuid, description);
84-
result.getLabels().addAll(getLabels(description));
85-
getDisplayName(description).ifPresent(result::setName);
8684
getLifecycle().scheduleTestCase(result);
8785
getLifecycle().startTestCase(uuid);
8886
}
@@ -125,8 +123,6 @@ public void testIgnored(final Description description) throws Exception {
125123
testCases.remove();
126124

127125
final TestResult result = createTestResult(uuid, description);
128-
result.getLabels().addAll(getLabels(description));
129-
getDisplayName(description).ifPresent(result::setName);
130126
result.setStatus(Status.SKIPPED);
131127
result.setStatusDetails(getIgnoredMessage(description));
132128
result.setStart(System.currentTimeMillis());
@@ -244,20 +240,28 @@ private StatusDetails getIgnoredMessage(final Description description) {
244240
}
245241

246242
private TestResult createTestResult(final String uuid, final Description description) {
247-
return new TestResult()
243+
final String className = description.getClassName();
244+
final String methodName = description.getMethodName();
245+
final String name = Objects.nonNull(methodName) ? methodName : className;
246+
final String fullName = Objects.nonNull(methodName) ? String.format("%s.%s", className, methodName) : className;
247+
248+
final TestResult testResult = new TestResult()
248249
.withUuid(uuid)
249250
.withHistoryId(getHistoryId(description))
250-
.withName(description.getMethodName())
251-
.withFullName(String.format("%s.%s", description.getClassName(), description.getMethodName()))
251+
.withName(name)
252+
.withFullName(fullName)
252253
.withLinks(getLinks(description))
253254
.withLabels(
254255
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()),
256+
new Label().withName("testClass").withValue(className),
257+
new Label().withName("testMethod").withValue(name),
258+
new Label().withName("suite").withValue(className),
258259
new Label().withName("host").withValue(getHostName()),
259260
new Label().withName("thread").withValue(getThreadName())
260261
);
262+
testResult.getLabels().addAll(getLabels(description));
263+
getDisplayName(description).ifPresent(testResult::setName);
264+
return testResult;
261265
}
262266

263267
}

allure-junit4/src/test/java/io/qameta/allure/junit4/FeatureCombinationsTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import io.qameta.allure.junit4.samples.AssumptionFailedTest;
66
import io.qameta.allure.junit4.samples.BrokenTest;
77
import io.qameta.allure.junit4.samples.FailedTest;
8+
import io.qameta.allure.junit4.samples.IgnoredClassTest;
89
import io.qameta.allure.junit4.samples.IgnoredTests;
910
import io.qameta.allure.junit4.samples.OneTest;
1011
import io.qameta.allure.junit4.samples.TaggedTests;
@@ -144,6 +145,16 @@ public void shouldProcessIgnoredTestDescription() throws Exception {
144145
.containsExactlyInAnyOrder("Test ignored (without reason)!", "Ignored for some reason");
145146
}
146147

148+
@Test
149+
@DisplayName("Test result for ignored class gets named by the class name")
150+
public void shouldSetNameForIgnoredClass() {
151+
core.run(Request.aClass(IgnoredClassTest.class));
152+
List<TestResult> testResults = results.getTestResults();
153+
assertThat(testResults)
154+
.extracting(TestResult::getName)
155+
.containsExactly("io.qameta.allure.junit4.samples.IgnoredClassTest");
156+
}
157+
147158
@Test
148159
@DisplayName("Test with steps")
149160
public void shouldAddStepsToTest() throws Exception {
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package io.qameta.allure.junit4.samples;
2+
3+
import org.junit.Ignore;
4+
import org.junit.Test;
5+
6+
/**
7+
* @author gladnik (Nikolai Gladkov)
8+
*/
9+
@Ignore
10+
public class IgnoredClassTest {
11+
12+
@Test
13+
public void ignoredAsPartOfTheIgnoredClassTest() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)