Java Code Examples for org.testng.xml.XmlSuite#ParallelMode

The following examples show how to use org.testng.xml.XmlSuite#ParallelMode . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@AllureFeatures.Descriptions
@Test(description = "Javadoc description of befores", dataProvider = "parallelConfiguration")
public void descriptionsBefores(final XmlSuite.ParallelMode mode, final int threadCount) {
    final String beforeClassDescription = "Before class description";
    final String beforeMethodDescription = "Before method description";
    final AllureResults results = runTestNgSuites(
            parallel(mode, threadCount),
            "suites/descriptions-test.xml"
    );
    final List<TestResultContainer> testContainers = results.getTestResultContainers();

    assertThat(testContainers).as("Test containers has not been written")
            .isNotEmpty()
            .filteredOn(container -> !container.getBefores().isEmpty())
            .extracting(container -> container.getBefores().get(0).getDescriptionHtml().trim())
            .as("Javadoc description of befores have not been processed")
            .containsOnly(beforeClassDescription, beforeMethodDescription);
}
 
Example 2
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@AllureFeatures.Fixtures
@Test(description = "Suite fixtures", dataProvider = "parallelConfiguration")
public void perSuiteFixtures(final XmlSuite.ParallelMode mode, final int threadCount) {
    String suiteName = "Test suite 12";
    String testTagName = "Test tag 12";
    String before1 = "beforeSuite1";
    String before2 = "beforeSuite2";
    String after1 = "afterSuite1";
    String after2 = "afterSuite2";

    final AllureResults results = runTestNgSuites(
            parallel(mode, threadCount),
            "suites/per-suite-fixtures-combination.xml"
    );

    List<TestResult> testResult = results.getTestResults();
    List<TestResultContainer> testContainers = results.getTestResultContainers();

    assertThat(testResult).as("Unexpected quantity of testng case results has been written").hasSize(1);
    List<String> testUuid = singletonList(testResult.get(0).getUuid());

    assertContainersChildren(testTagName, testContainers, testUuid);
    assertContainersChildren(suiteName, testContainers, getUidsByName(testContainers, testTagName));
    assertBeforeFixtures(suiteName, testContainers, before1, before2);
    assertAfterFixtures(suiteName, testContainers, after1, after2);
}
 
Example 3
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@AllureFeatures.Fixtures
@Test(description = "Test fixtures", dataProvider = "parallelConfiguration")
public void perTestTagFixtures(final XmlSuite.ParallelMode mode, final int threadCount) {
    String suiteName = "Test suite 13";
    String testTagName = "Test tag 13";
    String before1 = "beforeTest1";
    String before2 = "beforeTest2";
    String after1 = "afterTest1";
    String after2 = "afterTest2";

    final AllureResults results = runTestNgSuites(
            parallel(mode, threadCount),
            "suites/per-test-tag-fixtures-combination.xml"
    );

    List<TestResult> testResult = results.getTestResults();
    List<TestResultContainer> testContainers = results.getTestResultContainers();

    assertThat(testResult).as("Unexpected quantity of testng case results has been written").hasSize(1);
    List<String> testUuid = singletonList(testResult.get(0).getUuid());

    assertContainersChildren(testTagName, testContainers, testUuid);
    assertContainersChildren(suiteName, testContainers, getUidsByName(testContainers, testTagName));
    assertBeforeFixtures(testTagName, testContainers, before1, before2);
    assertAfterFixtures(testTagName, testContainers, after1, after2);
}
 
Example 4
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("unchecked")
@AllureFeatures.Fixtures
@Issue("304")
@Test(dataProvider = "parallelConfiguration")
public void shouldProcessFailedSetUps(final XmlSuite.ParallelMode mode, final int threadCount) {
    final AllureResults results = runTestNgSuites(parallel(mode, threadCount), "suites/gh-304.xml");

    assertThat(results.getTestResults())
            .extracting(TestResult::getName, TestResult::getStatus)
            .contains(tuple("skippedTest", Status.SKIPPED));

    assertThat(results.getTestResultContainers())
            .flatExtracting(TestResultContainer::getAfters)
            .extracting(FixtureResult::getName, FixtureResult::getStatus)
            .contains(tuple("afterAlways", Status.PASSED));

    assertThat(results.getTestResultContainers())
            .flatExtracting(TestResultContainer::getAfters)
            .filteredOn("name", "afterAlways")
            .flatExtracting(FixtureResult::getSteps)
            .extracting(StepResult::getName)
            .containsExactly(
                    "first", "second"
            );
}
 
Example 5
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Base
@Test(description = "Test with timeout", dataProvider = "parallelConfiguration")
public void testWithTimeout(final XmlSuite.ParallelMode mode, final int threadCount) {

    final String testNameWithTimeout = "testWithTimeout";
    final String testNameWithoutTimeout = "testWithoutTimeout";
    final AllureResults results = runTestNgSuites(parallel(mode, threadCount), "suites/tests-with-timeout.xml");
    List<TestResult> testResults = results.getTestResults();

    assertThat(testResults)
            .as("Test case results have not been written")
            .hasSize(2)
            .as("Unexpectedly passed status or stage of tests")
            .allMatch(testResult -> testResult.getStatus().equals(Status.PASSED) &&
                    testResult.getStage().equals(Stage.FINISHED))
            .extracting(TestResult::getName)
            .as("Unexpectedly passed name of tests")
            .containsOnlyElementsOf(asList(
                    testNameWithoutTimeout,
                    testNameWithTimeout)
            );
    assertThat(testResults)
            .flatExtracting(TestResult::getSteps)
            .as("No steps present for test with timeout")
            .hasSize(2)
            .extracting(StepResult::getName)
            .containsOnlyElementsOf(asList(
                    "Step of the test with timeout",
                    "Step of the test with no timeout")
            );
}
 
Example 6
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Fixtures
@Test(description = "Class fixtures", dataProvider = "parallelConfiguration")
public void perClassFixtures(final XmlSuite.ParallelMode mode, final int threadCount) {
    final AllureResults results = runTestNgSuites(
            parallel(mode, threadCount),
            "suites/per-class-fixtures-combination.xml"
    );
    assertThat(results.getTestResults())
            .extracting(TestResult::getName)
            .containsExactlyInAnyOrder("test1", "test2");

    assertThat(results.getTestResultContainers())
            .flatExtracting(TestResultContainer::getBefores)
            .extracting(FixtureResult::getName)
            .containsExactlyInAnyOrder("beforeClass");

    assertThat(results.getTestResultContainers())
            .flatExtracting(TestResultContainer::getAfters)
            .extracting(FixtureResult::getName)
            .containsExactlyInAnyOrder("afterClass");

    final TestResult test1 = findTestResultByName(results, "test1");
    final TestResult test2 = findTestResultByName(results, "test2");

    assertThat(results.getTestResultContainers())
            .flatExtracting(TestResultContainer::getChildren)
            .contains(test1.getUuid(), test2.getUuid());
}
 
Example 7
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@AllureFeatures.Fixtures
@Test(description = "Method fixtures", dataProvider = "parallelConfiguration")
public void perMethodFixtures(final XmlSuite.ParallelMode mode, final int threadCount) {
    String suiteName = "Test suite 11";
    String testTagName = "Test tag 11";
    String before1 = "io.qameta.allure.testng.samples.PerMethodFixtures.beforeMethod1";
    String before2 = "io.qameta.allure.testng.samples.PerMethodFixtures.beforeMethod2";
    String after1 = "io.qameta.allure.testng.samples.PerMethodFixtures.afterMethod1";
    String after2 = "io.qameta.allure.testng.samples.PerMethodFixtures.afterMethod2";

    final AllureResults results = runTestNgSuites(
            parallel(mode, threadCount),
            "suites/per-method-fixtures-combination.xml"
    );

    List<TestResult> testResults = results.getTestResults();
    List<TestResultContainer> testContainers = results.getTestResultContainers();

    assertThat(testResults).as("Unexpected quantity of testng case results has been written").hasSize(2);
    List<String> uuids = testResults.stream().map(TestResult::getUuid).collect(Collectors.toList());

    assertContainersChildren(testTagName, testContainers, uuids);
    assertContainersChildren(suiteName, testContainers, getUidsByName(testContainers, testTagName));
    assertContainersPerMethod(before1, testContainers, uuids);
    assertContainersPerMethod(before2, testContainers, uuids);
    assertContainersPerMethod(after1, testContainers, uuids);
    assertContainersPerMethod(after2, testContainers, uuids);
}
 
Example 8
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 5 votes vote down vote up
protected Consumer<TestNG> parallel(final XmlSuite.ParallelMode mode,
                                    final int threadCount) {
    return testNG -> {
        testNG.setParallel(mode);
        testNG.setThreadCount(threadCount);
    };
}
 
Example 9
Source File: AllureTestNgTest.java    From allure-java with Apache License 2.0 4 votes vote down vote up
@AllureFeatures.Fixtures
@AllureFeatures.Parallel
@Issue("219")
@Test(
        description = "Should not mix up fixtures during parallel run",
        dataProvider = "parallelConfiguration"
)
public void shouldAddCorrectBeforeMethodFixturesInCaseOfParallelRun(
        final XmlSuite.ParallelMode mode, final int threadCount) {
    final AllureResults results = runTestNgSuites(
            parallel(mode, threadCount),
            "suites/gh-219.xml"
    );

    final List<TestResultContainer> testContainers = results.getTestResultContainers();
    final List<TestResult> testResults = results.getTestResults();

    testResults.forEach(testResult -> {
        final List<FixtureResult> firstBefore = testContainers.stream()
                .filter(container -> container.getChildren().contains(testResult.getUuid()))
                .map(TestResultContainer::getBefores)
                .flatMap(Collection::stream)
                .collect(Collectors.toList());

        final List<FixtureResult> firstAfter = testContainers.stream()
                .filter(container -> container.getChildren().contains(testResult.getUuid()))
                .map(TestResultContainer::getAfters)
                .flatMap(Collection::stream)
                .collect(Collectors.toList());

        assertThat(firstBefore)
                .extracting(FixtureResult::getName)
                .contains(
                        "beforeTest",
                        "beforeClass",
                        "beforeMethod1",
                        "beforeMethod2"
                );


        assertThat(firstAfter)
                .extracting(FixtureResult::getName)
                .contains(
                        "afterTest",
                        "afterClass",
                        "afterMethod1",
                        "afterMethod2"
                );

    });
}