Skip to content

Commit 7de0c10

Browse files
author
Artem Eroshenko
authored
fixture container (via #541)
1 parent 959a016 commit 7de0c10

File tree

7 files changed

+93
-3
lines changed

7 files changed

+93
-3
lines changed

allure-testng/src/main/java/io/qameta/allure/testng/AllureTestNg.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,9 @@ public void onConfigurationFailure(final ITestResult itr) {
515515

516516
startTestCase(itr, parentUuid, uuid);
517517

518+
addChildToContainer(getUniqueUuid(itr.getTestContext()), uuid);
519+
addChildToContainer(getUniqueUuid(itr.getTestContext().getSuite()), uuid);
520+
addClassContainerChild(itr.getMethod().getTestClass(), uuid);
518521
// results created for configuration failure should not be considered as test cases.
519522
getLifecycle().updateTestCase(
520523
uuid,
@@ -747,12 +750,15 @@ private Consumer<TestResult> setStatus(final Status status, final StatusDetails
747750
}
748751

749752
private void addClassContainerChild(final ITestClass clazz, final String childUuid) {
753+
this.addChildToContainer(classContainerUuidStorage.get(clazz), childUuid);
754+
}
755+
756+
private void addChildToContainer(final String containerUuid, final String childUuid) {
750757
lock.writeLock().lock();
751758
try {
752-
final String parentUuid = classContainerUuidStorage.get(clazz);
753-
if (nonNull(parentUuid)) {
759+
if (nonNull(containerUuid)) {
754760
getLifecycle().updateTestContainer(
755-
parentUuid,
761+
containerUuid,
756762
container -> container.getChildren().add(childUuid)
757763
);
758764
}

allure-testng/src/test/java/io/qameta/allure/testng/AllureTestNgTest.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
import java.util.Collection;
5353
import java.util.List;
5454
import java.util.Objects;
55+
import java.util.Optional;
5556
import java.util.function.Consumer;
5657
import java.util.function.Predicate;
5758
import java.util.stream.Collectors;
@@ -1128,6 +1129,33 @@ public void shouldSupportFactoryOnConstructor() {
11281129
);
11291130
}
11301131

1132+
@DataProvider(name = "failedFixtures")
1133+
public Object[][] failedFixtures() {
1134+
return new Object[][]{
1135+
{"suites/failed-before-test-fixture.xml", "beforeTest"},
1136+
{"suites/failed-before-class-fixture.xml", "beforeClass"},
1137+
{"suites/failed-before-suite-fixture.xml", "beforeSuite"}
1138+
};
1139+
}
1140+
1141+
@Test(dataProvider = "failedFixtures")
1142+
@AllureFeatures.Fixtures
1143+
public void shouldAddBeforeFixtureToFakeTestResult(final String suite, final String fixture) {
1144+
System.out.println(suite);
1145+
System.out.println(fixture);
1146+
final AllureResults results = runTestNgSuites(suite);
1147+
final Optional<TestResult> result = results.getTestResults().stream()
1148+
.filter(r -> r.getName().contains(fixture))
1149+
.findAny();
1150+
assertThat(result).as("Before failed fake test result").isNotEmpty();
1151+
final Optional<TestResultContainer> befores = results.getTestResultContainers().stream()
1152+
.filter(c -> Objects.nonNull(c.getBefores()) && c.getBefores().size() > 0)
1153+
.findAny();
1154+
assertThat(result).as("Before failed configuration container").isNotEmpty();
1155+
assertThat(befores.get().getChildren())
1156+
.contains(result.get().getUuid());
1157+
}
1158+
11311159
@Step("Run testng suites {suites}")
11321160
private AllureResults runTestNgSuites(final Consumer<TestNG> configurer,
11331161
final String... suites) {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2019 Qameta Software OÜ
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package io.qameta.allure.testng.samples;
17+
18+
import org.testng.annotations.BeforeClass;
19+
import org.testng.annotations.Test;
20+
21+
import static io.qameta.allure.Allure.step;
22+
23+
/**
24+
* @author charlie (Dmitry Baev).
25+
*/
26+
public class FailedBeforeClass {
27+
28+
@BeforeClass
29+
public void beforeClass() throws Exception {
30+
step("before class step");
31+
throw new RuntimeException();
32+
}
33+
34+
@Test
35+
public void skipped() throws Exception {
36+
}
37+
}

allure-testng/src/test/java/io/qameta/allure/testng/samples/FailedBeforeMethod.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
import org.testng.annotations.BeforeMethod;
1919
import org.testng.annotations.Test;
2020

21+
import static io.qameta.allure.Allure.step;
22+
2123
/**
2224
* @author charlie (Dmitry Baev).
2325
*/
2426
public class FailedBeforeMethod {
2527

2628
@BeforeMethod
2729
public void beforeMethod() throws Exception {
30+
step("before method step");
2831
throw new RuntimeException();
2932
}
3033

allure-testng/src/test/java/io/qameta/allure/testng/samples/FailedBeforeSuite.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
import org.testng.annotations.BeforeSuite;
1919
import org.testng.annotations.Test;
2020

21+
import static io.qameta.allure.Allure.step;
22+
2123
/**
2224
* @author charlie (Dmitry Baev).
2325
*/
2426
public class FailedBeforeSuite {
2527

2628
@BeforeSuite
2729
public void beforeSuite() throws Exception {
30+
step("before suite step");
2831
throw new RuntimeException();
2932
}
3033

allure-testng/src/test/java/io/qameta/allure/testng/samples/FailedBeforeTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@
1818
import org.testng.annotations.BeforeTest;
1919
import org.testng.annotations.Test;
2020

21+
import static io.qameta.allure.Allure.step;
22+
2123
/**
2224
* @author charlie (Dmitry Baev).
2325
*/
2426
public class FailedBeforeTest {
2527

2628
@BeforeTest
2729
public void beforeTest() throws Exception {
30+
step("before test step");
2831
throw new RuntimeException();
2932
}
3033

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
3+
4+
<suite name="Fixtures Support">
5+
<test name="Test fixtures">
6+
<classes>
7+
<class name="io.qameta.allure.testng.samples.FailedBeforeClass"/>
8+
</classes>
9+
</test>
10+
</suite>

0 commit comments

Comments
 (0)