ru.yandex.qatools.allure.model.TestSuiteResult Java Examples

The following examples show how to use ru.yandex.qatools.allure.model.TestSuiteResult. 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: AllureFileUtilsTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldUnmarshalSuiteFiles() throws Exception {
    TestSuiteResult first = new TestSuiteResult().withName("first");
    TestSuiteResult second = new TestSuiteResult().withName("second");

    File folder = this.folder.newFolder();
    File firstFile = new File(folder, "first-testsuite.xml");
    JAXB.marshal(first, firstFile);

    File secondFile = new File(folder, "second-testsuite.xml");
    JAXB.marshal(second, secondFile);

    List<TestSuiteResult> suites = AllureFileUtils.unmarshalSuites(folder);
    assertThat(suites, hasSize(2));

    assertThat(suites, containsInAnyOrder(first, second));
}
 
Example #2
Source File: WriteTestSuiteResultTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void invalidCharacterTest() throws Exception {
    TestSuiteResult testSuiteResult = new TestSuiteResult()
            .withName("somename");

    String titleWithInvalidXmlCharacter = String.valueOf(Character.toChars(0x0));
    testSuiteResult.setTitle(titleWithInvalidXmlCharacter);

    AllureResultsUtils.writeTestSuiteResult(testSuiteResult);

    Validator validator = AllureModelUtils.getAllureSchemaValidator();

    for (File each : listTestSuiteFiles(resultsDirectory)) {
        validator.validate(new StreamSource(each));
    }
}
 
Example #3
Source File: AllureGuiceModule.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Override
protected void configure() {
    bind(File[].class).annotatedWith(ResultDirectories.class).toInstance(inputDirectories);
    bind(ClassLoader.class).annotatedWith(PluginClassLoader.class).toInstance(classLoader);

    bind(new TypeLiteral<Reader<TestSuiteResult>>() {
    }).to(TestSuiteReader.class);
    bind(new TypeLiteral<Reader<TestCaseResult>>() {
    }).to(TestCaseReader.class);
    bind(new TypeLiteral<Reader<Environment>>() {
    }).to(EnvironmentReader.class);
    bind(new TypeLiteral<Reader<AttachmentInfo>>() {
    }).to(AttachmentReader.class);

    bind(PluginLoader.class).to(DefaultPluginLoader.class);
    bind(AttachmentsIndex.class).to(DefaultAttachmentsIndex.class);

    bind(TestCaseConverter.class).to(DefaultTestCaseConverter.class);
}
 
Example #4
Source File: AllureLifecycleTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void allureClearStorageTest() {
    String suiteUid = UUID.randomUUID().toString();
    TestSuiteResult testSuite = fireTestSuiteStart(suiteUid);
    TestCaseResult testCase = fireTestCaseStart(suiteUid);
    assertThat(testSuite.getTestCases(), hasSize(1));
    assertEquals(testSuite.getTestCases().get(0), testCase);

    Step parentStep = fireStepStart();
    Step nestedStep = fireStepStart();
    fireStepFinished();

    assertThat(parentStep.getSteps(), hasSize(1));
    assertTrue(parentStep.getSteps().get(0) == nestedStep);

    fireStepFinished();
    fireClearStepStorage();

    assertThat(testCase.getSteps(), hasSize(0));
    fireClearTestStorage();
    TestCaseResult afterClearing = Allure.LIFECYCLE.getTestCaseStorage().get();
    assertFalse(testCase == afterClearing);
    checkTestCaseIsNew(afterClearing);

}
 
Example #5
Source File: AllureListenerTimeoutTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldNotLoseEventsFromTestWithTimeout() throws Exception {
    TestSuiteResult result = JAXB.unmarshal(
            listTestSuiteFiles(resultsDirectory).iterator().next(),
            TestSuiteResult.class
    );

    assertThat(result.getTestCases(), not(empty()));
    assertThat(
            String.format(
                    "Result should contains title '%s'",
                    TestWithTimeoutAnnotation.NAME
            ),
            result.getTestCases().iterator().next().getTitle(),
            is(TestWithTimeoutAnnotation.NAME)
    );
}
 
Example #6
Source File: AllureTestListenerConfigMethodsTest.java    From allure1 with Apache License 2.0 6 votes vote down vote up
private void validateTestSuiteResult(TestSuiteResult testSuiteResult) {
    String brokenMethod = testSuiteResult.getName().replace(SUITE_PREFIX, "config");
    for (TestCaseResult result : testSuiteResult.getTestCases()) {
        String methodName = result.getName();
        Status status = result.getStatus();
        Status expectedStatus = Status.CANCELED;
        if (brokenMethod.startsWith(methodName)) {
            expectedStatus = Status.BROKEN;
        }
        if (brokenMethod.contains("After") && methodName.equalsIgnoreCase("test")) {
            expectedStatus = Status.PASSED;
        }
        assertThat(String.format("Wrong status for test <%s>, method <%s>", brokenMethod, methodName),
                status, equalTo(expectedStatus));
    }
}
 
Example #7
Source File: Allure.java    From allure1 with Apache License 2.0 6 votes vote down vote up
/**
 * Process TestSuiteFinishedEvent. Using event.getUid() to access testSuite.
 * Then remove this suite from storage and marshal testSuite to xml using
 * AllureResultsUtils.writeTestSuiteResult()
 *
 * @param event to process
 */
public void fire(TestSuiteFinishedEvent event) {
    String suiteUid = event.getUid();

    TestSuiteResult testSuite = testSuiteStorage.remove(suiteUid);
    if (testSuite == null) {
        return;
    }
    event.process(testSuite);

    testSuite.setVersion(getVersion());
    testSuite.getLabels().add(AllureModelUtils.createProgrammingLanguageLabel());

    writeTestSuiteResult(testSuite);

    notifier.fire(event);
}
 
Example #8
Source File: Allure1Plugin.java    From allure2 with Apache License 2.0 5 votes vote down vote up
private Stream<TestSuiteResult> xmlFiles(final Path source) {
    try {
        return AllureUtils.listTestSuiteXmlFiles(source)
                .stream()
                .map(this::readXmlTestSuiteFile)
                .filter(Optional::isPresent)
                .map(Optional::get);
    } catch (IOException e) {
        LOGGER.error("Could not list allure1 xml files", e);
        return Stream.empty();
    }
}
 
Example #9
Source File: TestSuiteStorageTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void removeTest() throws Exception {
    TestSuiteResult testSuite = testSuiteStorage.get("a");
    assertTrue(testSuite == testSuiteStorage.get("a"));
    testSuiteStorage.remove("a");
    assertFalse(testSuite == testSuiteStorage.get("a"));
}
 
Example #10
Source File: WriteTestSuiteResultTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldCloseResultFileTest() throws Exception {
    File resultFile = new File(folder.getRoot(), "suite.xml");

    AllureResultsUtils.writeTestSuiteResult(new TestSuiteResult(), resultFile);

    assertTrue(resultFile.exists());

    Files.delete(resultFile.toPath());
    assertFalse(resultFile.exists());
}
 
Example #11
Source File: BadXmlCharacterEscapeHandlerTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void dataWithInvalidCharacterTest() throws Exception {
    AllureResultsUtils.writeTestSuiteResult(result, testSuiteResultFile);

    Validator validator = AllureModelUtils.getAllureSchemaValidator();
    validator.validate(new StreamSource(testSuiteResultFile));

    TestSuiteResult testSuite = JAXB.unmarshal(testSuiteResultFile, TestSuiteResult.class);
    assertThat(testSuite.getName(), is("name-and-кириллицей-also"));
    assertTrue(testSuite.getTitle().startsWith("prefix "));
    assertTrue(testSuite.getTitle().endsWith(" suffix"));
}
 
Example #12
Source File: AllureReportGenerator.java    From AuTe-Framework with Apache License 2.0 5 votes vote down vote up
private AllurePreparedData buildTestSuiteData(
        File resultDirectory,
        String group,
        Map<Scenario, List<StepResult>> scenarioListMap
) {
    File dataFile = new File(resultDirectory + File.separator + UUID.randomUUID() + "-testsuite.json");
    TestSuiteResult suiteResult = new TestSuiteResult()
            .withName(group)
            .withTestCases(buildTestCasesData(resultDirectory, group, scenarioListMap));
    return AllurePreparedData.of(dataFile, suiteResult);
}
 
Example #13
Source File: ListenersNotifierTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void testsuiteEventTest() throws Exception {
    allure.fire(new TestSuiteEvent() {
        @Override
        public String getUid() {
            return "";
        }

        @Override
        public void process(TestSuiteResult context) {

        }
    });
    assertThat(listener.get(SimpleListener.EventType.TESTSUITE_EVENT), is(1));
}
 
Example #14
Source File: AllureLifecycleTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
public TestSuiteResult fireCustomTestSuiteEvent(String uid) {
    Allure.LIFECYCLE.fire(new ChangeTestSuiteTitleEvent(uid, "new.suite.title"));
    TestSuiteResult testSuite = Allure.LIFECYCLE.getTestSuiteStorage().get(uid);
    assertNotNull(testSuite);
    assertThat(testSuite.getTitle(), is("new.suite.title"));
    return testSuite;
}
 
Example #15
Source File: AllureLifecycleTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
public TestSuiteResult fireTestSuiteStart(String uid) {
    Allure.LIFECYCLE.fire(new TestSuiteStartedEvent(uid, "some.suite.name"));
    TestSuiteResult testSuite = Allure.LIFECYCLE.getTestSuiteStorage().get(uid);
    assertNotNull(testSuite);
    assertThat(testSuite.getName(), is("some.suite.name"));
    assertThat(testSuite.getTestCases(), hasSize(0));
    return testSuite;
}
 
Example #16
Source File: AllureFileUtils.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Find and unmarshal all test suite files in given directories.
 *
 * @throws IOException if any occurs.
 * @see #unmarshal(File)
 */
public static List<TestSuiteResult> unmarshalSuites(File... directories) throws IOException {
    List<TestSuiteResult> results = new ArrayList<>();

    List<File> files = listTestSuiteFiles(directories);

    for (File file : files) {
        results.add(unmarshal(file));
    }
    return results;
}
 
Example #17
Source File: Allure1Plugin.java    From allure2 with Apache License 2.0 5 votes vote down vote up
private Optional<TestSuiteResult> readJsonTestSuiteFile(final Path source) {
    try (InputStream is = Files.newInputStream(source)) {
        return Optional.of(jsonMapper.readValue(is, TestSuiteResult.class));
    } catch (IOException e) {
        LOGGER.error("Could not read json result {}: {}", source, e);
        return Optional.empty();
    }
}
 
Example #18
Source File: AllureTestListenerConfigMethodsTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void validateCanceledTest() throws IOException {
    List<TestSuiteResult> results = AllureFileUtils.unmarshalSuites(resultsDir.toFile());
    for (TestSuiteResult result : results) {
        validateTestSuiteResult(result);
    }
}
 
Example #19
Source File: Allure1Plugin.java    From allure2 with Apache License 2.0 5 votes vote down vote up
private Stream<TestSuiteResult> jsonFiles(final Path source) {
    try {
        return AllureUtils.listTestSuiteJsonFiles(source)
                .stream()
                .map(this::readJsonTestSuiteFile)
                .filter(Optional::isPresent)
                .map(Optional::get);
    } catch (IOException e) {
        LOGGER.error("Could not list allure1 json files", e);
        return Stream.empty();
    }
}
 
Example #20
Source File: Allure1Plugin.java    From allure2 with Apache License 2.0 5 votes vote down vote up
private Optional<TestSuiteResult> readXmlTestSuiteFile(final Path source) {
    try (InputStream is = Files.newInputStream(source)) {
        return Optional.of(xmlMapper.readValue(is, TestSuiteResult.class));
    } catch (IOException e) {
        LOGGER.error("Could not read xml result {}: {}", source, e);
    }
    return Optional.empty();
}
 
Example #21
Source File: Allure.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Process TestSuiteEvent. You can use this method to change current
 * testSuite context. Using event.getUid() to access testSuite.
 *
 * @param event to process
 */
public void fire(TestSuiteEvent event) {
    TestSuiteResult testSuite = testSuiteStorage.get(event.getUid());
    event.process(testSuite);

    notifier.fire(event);
}
 
Example #22
Source File: AllureTestListenerSuiteNameTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldContainsBothSuitesWithDifferentNames() throws Exception {
    Collection<File> files = listTestSuiteFiles(resultsDir);
    assumeThat(files, hasSize(2));
    List<String> names = new ArrayList<>();
    for (File file : files) {
        TestSuiteResult result = JAXB.unmarshal(file, TestSuiteResult.class);
        names.add(result.getName());
    }

    assumeThat(names, containsInAnyOrder(
            "Test suite tag : Test tag by classes[param1=val1]",
            "Test suite tag : Test tag by classes 2[param1=val1]"
    ));
}
 
Example #23
Source File: TestSuiteStartedEvent.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Sets to testSuite start time, name, title, description and labels
 *
 * @param testSuite to change
 */
@Override
public void process(TestSuiteResult testSuite) {
    testSuite.setStart(System.currentTimeMillis());
    testSuite.setName(getName());
    testSuite.setTitle(getTitle());
    testSuite.setDescription(getDescription());
    testSuite.setLabels(getLabels());
}
 
Example #24
Source File: AllureResultsUtils.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Marshal {@link ru.yandex.qatools.allure.model.TestSuiteResult} to specified file
 * uses {@link BadXmlCharacterFilterWriter}. Name of file generated uses
 * {@link ru.yandex.qatools.allure.config.AllureNamingUtils#generateTestSuiteFileName()}
 *
 * @param testSuite to marshal
 */
public static void writeTestSuiteResult(TestSuiteResult testSuite, File testSuiteResultFile) {
    try (BadXmlCharacterFilterWriter writer = new BadXmlCharacterFilterWriter(testSuiteResultFile)) {
        marshaller(TestSuiteResult.class).marshal(
                new ObjectFactory().createTestSuite(testSuite),
                writer
        );
    } catch (Exception e) {
        LOGGER.error("Error while marshaling testSuite", e);
    }
}
 
Example #25
Source File: AllureTestListenerMultipleSuitesTest.java    From allure1 with Apache License 2.0 5 votes vote down vote up
@Test
public void validatePendingTest() throws IOException {
    TestSuiteResult testSuite = AllureFileUtils.unmarshalSuites(resultsDir.toFile()).get(0);
    TestCaseResult testResult = testSuite.getTestCases().get(0);

    assertThat(testResult.getStatus(), equalTo(Status.PENDING));  
    assertThat(testResult.getDescription().getValue(), equalTo("This is pending test"));
}
 
Example #26
Source File: AllureShutdownHook.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Create fake test case, which will used for mark suite as interrupted.
 */
public TestCaseResult createFakeTestcaseWithWarning(TestSuiteResult testSuite) {
    return new TestCaseResult()
            .withName(testSuite.getName())
            .withTitle(testSuite.getName())
            .withStart(testSuite.getStart())
            .withStop(System.currentTimeMillis())
            .withFailure(new Failure().withMessage("Test suite was interrupted, some test cases may be lost"))
            .withStatus(Status.BROKEN);
}
 
Example #27
Source File: AllureShutdownHook.java    From allure1 with Apache License 2.0 5 votes vote down vote up
/**
 * Mark unfinished test cases as interrupted for each unfinished test suite, then write
 * test suite result
 * @see #createFakeTestcaseWithWarning(ru.yandex.qatools.allure.model.TestSuiteResult)
 * @see #markTestcaseAsInterruptedIfNotFinishedYet(ru.yandex.qatools.allure.model.TestCaseResult)
 */
@Override
public void run() {
    for (Map.Entry<String, TestSuiteResult> entry : testSuites) {
        for (TestCaseResult testCase : entry.getValue().getTestCases()) {
            markTestcaseAsInterruptedIfNotFinishedYet(testCase);
        }
        entry.getValue().getTestCases().add(createFakeTestcaseWithWarning(entry.getValue()));

        Allure.LIFECYCLE.fire(new TestSuiteFinishedEvent(entry.getKey()));
    }
}
 
Example #28
Source File: TestCaseReader.java    From allure1 with Apache License 2.0 4 votes vote down vote up
@Inject
public TestCaseReader(Reader<TestSuiteResult> suiteResultsReader) {
    testSuites = suiteResultsReader.iterator();
}
 
Example #29
Source File: TestSuiteReader.java    From allure1 with Apache License 2.0 4 votes vote down vote up
@Override
public Iterator<TestSuiteResult> iterator() {
    return new TestSuiteResultIterator();
}
 
Example #30
Source File: ChangeTestSuiteTitleEvent.java    From allure1 with Apache License 2.0 4 votes vote down vote up
@Override
public void process(TestSuiteResult context) {
    context.setTitle(title);
}