Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -500,6 +500,9 @@ public void onConfigurationFailure(final ITestResult itr) {

startTestCase(itr, parentUuid, uuid);

addChildToContainer(getUniqueUuid(itr.getTestContext()), uuid);
addChildToContainer(getUniqueUuid(itr.getTestContext().getSuite()), uuid);
addClassContainerChild(itr.getMethod().getTestClass(), uuid);
// results created for configuration failure should not be considered as test cases.
getLifecycle().updateTestCase(
uuid,
Expand Down Expand Up @@ -732,12 +735,15 @@ private Consumer<TestResult> setStatus(final Status status, final StatusDetails
}

private void addClassContainerChild(final ITestClass clazz, final String childUuid) {
this.addChildToContainer(classContainerUuidStorage.get(clazz), childUuid);
}

private void addChildToContainer(final String containerUuid, final String childUuid) {
lock.writeLock().lock();
try {
final String parentUuid = classContainerUuidStorage.get(clazz);
if (nonNull(parentUuid)) {
if (nonNull(containerUuid)) {
getLifecycle().updateTestContainer(
parentUuid,
containerUuid,
container -> container.getChildren().add(childUuid)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.Consumer;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand Down Expand Up @@ -1113,6 +1114,33 @@ public void shouldSupportFactoryOnConstructor() {
);
}

@DataProvider(name = "failedFixtures")
public Object[][] failedFixtures() {
return new Object[][]{
{"suites/failed-before-test-fixture.xml", "beforeTest"},
{"suites/failed-before-class-fixture.xml", "beforeClass"},
{"suites/failed-before-suite-fixture.xml", "beforeSuite"}
};
}

@Test(dataProvider = "failedFixtures")
@AllureFeatures.Fixtures
public void shouldAddBeforeFixtureToFakeTestResult(final String suite, final String fixture) {
System.out.println(suite);
System.out.println(fixture);
final AllureResults results = runTestNgSuites(suite);
final Optional<TestResult> result = results.getTestResults().stream()
.filter(r -> r.getName().contains(fixture))
.findAny();
assertThat(result).as("Before failed fake test result").isNotEmpty();
final Optional<TestResultContainer> befores = results.getTestResultContainers().stream()
.filter(c -> Objects.nonNull(c.getBefores()) && c.getBefores().size() > 0)
.findAny();
assertThat(result).as("Before failed configuration container").isNotEmpty();
assertThat(befores.get().getChildren())
.contains(result.get().getUuid());
}

@Step("Run testng suites {suites}")
private AllureResults runTestNgSuites(final Consumer<TestNG> configurer,
final String... suites) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright 2019 Qameta Software OÜ
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.qameta.allure.testng.samples;

import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;

import static io.qameta.allure.Allure.step;

/**
* @author charlie (Dmitry Baev).
*/
public class FailedBeforeClass {

@BeforeClass
public void beforeClass() throws Exception {
step("before class step");
throw new RuntimeException();
}

@Test
public void skipped() throws Exception {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

import static io.qameta.allure.Allure.step;

/**
* @author charlie (Dmitry Baev).
*/
public class FailedBeforeMethod {

@BeforeMethod
public void beforeMethod() throws Exception {
step("before method step");
throw new RuntimeException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

import static io.qameta.allure.Allure.step;

/**
* @author charlie (Dmitry Baev).
*/
public class FailedBeforeSuite {

@BeforeSuite
public void beforeSuite() throws Exception {
step("before suite step");
throw new RuntimeException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import static io.qameta.allure.Allure.step;

/**
* @author charlie (Dmitry Baev).
*/
public class FailedBeforeTest {

@BeforeTest
public void beforeTest() throws Exception {
step("before test step");
throw new RuntimeException();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Fixtures Support">
<test name="Test fixtures">
<classes>
<class name="io.qameta.allure.testng.samples.FailedBeforeClass"/>
</classes>
</test>
</suite>