Java Code Examples for org.junit.platform.launcher.TestIdentifier#isTest()

The following examples show how to use org.junit.platform.launcher.TestIdentifier#isTest() . 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: AllureJunitPlatform.java    From allure-java with Apache License 2.0 6 votes vote down vote up
@Override
public void executionFinished(final TestIdentifier testIdentifier,
                              final TestExecutionResult testExecutionResult) {
    // skip root
    if (!testIdentifier.getParentId().isPresent()) {
        return;
    }
    final Status status = extractStatus(testExecutionResult);
    final StatusDetails statusDetails = testExecutionResult.getThrowable()
            .flatMap(ResultsUtils::getStatusDetails)
            .orElse(null);

    if (testIdentifier.isTest()) {
        stopTestCase(testIdentifier, status, statusDetails);
    } else if (testExecutionResult.getStatus() != TestExecutionResult.Status.SUCCESSFUL) {
        // report failed containers as fake test results
        startTestCase(testIdentifier);
        stopTestCase(testIdentifier, status, statusDetails);
    }
    stopTestContainer(testIdentifier);
}
 
Example 2
Source File: AllureJunitPlatform.java    From allure-java with Apache License 2.0 6 votes vote down vote up
private void stopTestContainer(final TestIdentifier testIdentifier) {
    final Optional<String> maybeUuid = containers.get(testIdentifier);
    if (!maybeUuid.isPresent()) {
        return;
    }
    final String uuid = maybeUuid.get();
    final TestPlan context = testPlanStorage.get();
    final Set<String> children = Optional.ofNullable(context)
            .map(tp -> tp.getDescendants(testIdentifier))
            .orElseGet(Collections::emptySet)
            .stream()
            .filter(TestIdentifier::isTest)
            .map(tests::get)
            .filter(Optional::isPresent)
            .map(Optional::get)
            .collect(Collectors.toCollection(HashSet::new));

    if (testIdentifier.isTest()) {
        tests.get(testIdentifier).ifPresent(children::add);
    }

    getLifecycle().updateTestContainer(uuid, container -> container.setChildren(children));
    getLifecycle().stopTestContainer(uuid);
    getLifecycle().writeTestContainer(uuid);
}
 
Example 3
Source File: TestPlanExecutionReport.java    From junit5-extensions with MIT License 6 votes vote down vote up
public final Builder addResult(TestIdentifier identifier, TestExecutionResult result) {
  DisplayName displayName = getDisplayName(identifier);

  if (identifier.isTest()) {
    testsBuilder().add(displayName);
  }

  switch (result.getStatus()) {
    case SUCCESSFUL:
      successfulBuilder().add(displayName);
      return this;
    case FAILED:
      failuresBuilder().put(displayName, result.getThrowable().orElse(null));
      return this;
    default:
      throw new AssertionError("Unhandled case in enum: " + result.getStatus());
  }
}
 
Example 4
Source File: OutputCapturingTestListener.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
@Override
public void executionFinished(TestIdentifier identifier, TestExecutionResult result) {

    CapturedOutputStream outputStream = outputStreamMap.remove(identifier.getUniqueId());
    if (null == outputStream) {
        return;
    }

    OutputCapture.deregister();

    if (isQuiet) {
        if (identifier.isTest()) {
            if (!SUCCESSFUL.equals(result.getStatus())) {
                outputStream.output.forEach(testLogger::info);
                outputStream.output.clear();
            }
        }
    }
}
 
Example 5
Source File: FlatPrintingTestListener.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
@Override
public void executionStarted(TestIdentifier testIdentifier) {

    startTimes.putIfAbsent(testIdentifier.getUniqueId(), System.currentTimeMillis());

    if (!testIdentifier.getParentId().isPresent()) {
        if (!testPlan.getChildren(testIdentifier).isEmpty()) {
            String message = "Test run started (" + testIdentifier.getDisplayName() + ")";
            debugOrInfo(colorTheme.info().format(message));
        }
    }

    if (testIdentifier.isTest()) {

        String testName = configuration.formatIdentifier(testPlan, testIdentifier);
        debugOrInfo("Test " + testName + " started");
    }
}
 
Example 6
Source File: AllureJunitPlatform.java    From allure-java with Apache License 2.0 5 votes vote down vote up
@Override
public void executionStarted(final TestIdentifier testIdentifier) {
    // skip root
    if (!testIdentifier.getParentId().isPresent()) {
        return;
    }
    // create container for every TestIdentifier. We need containers for tests in order
    // to support method fixtures.
    startTestContainer(testIdentifier);

    if (testIdentifier.isTest()) {
        startTestCase(testIdentifier);
    }
}
 
Example 7
Source File: AllureJunitPlatform.java    From allure-java with Apache License 2.0 5 votes vote down vote up
private void reportNested(final TestPlan testPlan,
                          final TestIdentifier testIdentifier,
                          final Status status,
                          final StatusDetails statusDetails,
                          final Set<TestIdentifier> visited) {
    final Set<TestIdentifier> children = testPlan.getChildren(testIdentifier);
    if (testIdentifier.isTest() || children.isEmpty()) {
        startTestCase(testIdentifier);
        stopTestCase(testIdentifier, status, statusDetails);
    }
    visited.add(testIdentifier);
    children.stream()
            .filter(id -> !visited.contains(id))
            .forEach(child -> reportNested(testPlan, child, status, statusDetails, visited));
}
 
Example 8
Source File: TestPlanExecutionReport.java    From junit5-extensions with MIT License 5 votes vote down vote up
public final Builder addSkipped(TestIdentifier identifier, @Nullable String reason) {
  DisplayName displayName = getDisplayName(identifier);

  if (identifier.isTest()) {
    testsBuilder().add(displayName);
  }

  skippedBuilder().put(displayName, reason);

  return this;
}
 
Example 9
Source File: TreePrintingTestListener.java    From sbt-jupiter-interface with Apache License 2.0 3 votes vote down vote up
@Override
public void executionSkipped(TestIdentifier testIdentifier, String reason) {

    maybeIncreaseIndent(testIdentifier);

    String fqn = colorTheme.info().format(testIdentifier.getDisplayName());
    String prefix = testIdentifier.isTest() ? colorTheme.ignoreCount().format("o ") : "";

    log(prefix + fqn);
}
 
Example 10
Source File: TreePrintingTestListener.java    From sbt-jupiter-interface with Apache License 2.0 3 votes vote down vote up
@Override
public void executionStarted(TestIdentifier testIdentifier) {

    maybeIncreaseIndent(testIdentifier);

    String fqn = colorTheme.info().format(testIdentifier.getDisplayName());
    String prefix = testIdentifier.isTest() ? colorTheme.successful().format("+ ") : "";

    log(prefix + fqn);
}