Java 类org.junit.platform.launcher.TestIdentifier 实例源码

项目:allure-java    文件:AllureJunit5.java   
@Override
public void executionStarted(final TestIdentifier testIdentifier) {
    if (testIdentifier.isTest()) {
        final Optional<MethodSource> methodSource = testIdentifier.getSource()
                .filter(MethodSource.class::isInstance)
                .map(MethodSource.class::cast);
        final String uuid = tests.get();
        final TestResult result = new TestResult()
                .withUuid(uuid)
                .withName(testIdentifier.getDisplayName())
                .withLabels(getTags(testIdentifier))
                .withHistoryId(getHistoryId(testIdentifier))
                .withStage(Stage.RUNNING);

        methodSource.ifPresent(source -> {
            result.setDescription(getDescription(source));
            result.getLabels().add(new Label().withName("suite").withValue(getSuite(source)));
            result.getLabels().add(new Label().withName("package").withValue(source.getClassName()));
        });

        getLifecycle().scheduleTestCase(result);
        getLifecycle().startTestCase(uuid);
    }
}
项目:junit5-extensions    文件:TestPlanExecutionReport.java   
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());
  }
}
项目:junit5-extensions    文件:TestPlanExecutionReport.java   
private DisplayName getDisplayName(TestIdentifier testIdentifier) {
  LinkedList<String> names = new LinkedList<>();
  Optional<TestIdentifier> id = Optional.of(testIdentifier);
  do {
    TestIdentifier identifier = id.get();
    Optional<ClassSource> classSource = identifier.getSource()
        .filter(source -> source instanceof ClassSource)
        .map(source -> (ClassSource) source)
        .filter(source -> !source.getPosition().isPresent())
        .filter(source -> classesToSkip.contains(source.getJavaClass()));
    if (classSource.isPresent()) {
      break;
    }

    names.addFirst(identifier.getDisplayName());

    id = id.flatMap(testPlan::getParent);
  } while (id.isPresent());

  return DisplayName.create(names);
}
项目:allure-java    文件:AllureJunit5.java   
@Override
public void executionFinished(final TestIdentifier testIdentifier, final TestExecutionResult testExecutionResult) {
    if (testIdentifier.isTest()) {
        final String uuid = tests.get();
        tests.remove();
        getLifecycle().updateTestCase(uuid, result -> {
            result.setStage(Stage.FINISHED);
            switch (testExecutionResult.getStatus()) {
                case FAILED:
                    testExecutionResult.getThrowable().ifPresent(throwable -> {
                        result.setStatus(getStatus(throwable));
                        result.setStatusDetails(ResultsUtils.getStatusDetails(throwable).orElse(null));
                    });
                    break;
                case SUCCESSFUL:
                    result.setStatus(PASSED);
                    break;
                default:
                    result.setStatus(SKIPPED);
                    testExecutionResult.getThrowable().ifPresent(throwable ->
                            result.setStatusDetails(ResultsUtils.getStatusDetails(throwable).orElse(null))
                    );
                    break;
            }
        });
        getLifecycle().stopTestCase(uuid);
        getLifecycle().writeTestCase(uuid);
    }
}
项目:junit5-extensions    文件:TestPlanExecutionReport.java   
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;
}
项目:pitest-junit5-plugin    文件:TestIdentifiers.java   
public static Description toDescription(TestIdentifier testIdentifier) {
    String className = testIdentifier.getSource().map(source -> {
        if (source instanceof ClassSource) {
            return ((ClassSource) source).getClassName();
        } else if (source instanceof MethodSource) {
            return ((MethodSource) source).getClassName();
        }

        return null;
    }).orElse(null);

    return new Description(testIdentifier.getDisplayName(), className);
}
项目:verify-matching-service-adapter    文件:TestStatusPrintingListener.java   
@Override
public void executionStarted(TestIdentifier testIdentifier) {
    super.executionStarted(testIdentifier);
    if (testIdentifier.isTest()) {
        System.out.println(RUNNING_TEST + testIdentifier.getDisplayName());
    }
}
项目:verify-matching-service-adapter    文件:TestStatusPrintingListener.java   
@Override
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
    super.executionFinished(testIdentifier, testExecutionResult);
    if (testIdentifier.isTest()) {
        Status status = testExecutionResult.getStatus();
        Color color = Color.valueOf(status);
        printMessage(color, STATUS + status);
        printFailureMessage(testIdentifier, testExecutionResult, color);
        System.out.println();
    }
}
项目:jovial    文件:SerializingListener.java   
@Override
public void executionSkipped(TestIdentifier testIdentifier, String reason) {
    Map<String, Object> data = new HashMap<>();
    data.put("type", "executionSkipped");
    data.put("reason", reason);
    writeData(testIdentifier, data);
}
项目:jovial    文件:SerializingListener.java   
@Override
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
    Map<String, Object> data = new HashMap<>();
    data.put("type", "executionFinished");
    data.put("success", testExecutionResult.getStatus() == TestExecutionResult.Status.SUCCESSFUL);
    data.put("throwable", testExecutionResult.getThrowable().orElse(null));
    writeData(testIdentifier, data);
}
项目:jovial    文件:SerializingListener.java   
private void writeData(TestIdentifier id, Map<String, Object> data) {
    try {
        data.put("uniqueId", id.getUniqueId());
        data.put("parentId", id.getParentId().orElse(null));
        data.put("displayName", id.getDisplayName());
        data.put("container", id.isContainer());
        stream.writeObject(data);
    } catch (IOException e) {
        System.err.println("Could not write event: " + data);
    }
}
项目:allure-java    文件:CustomListener.java   
@Override
protected String getHistoryId(final TestIdentifier testIdentifier) {
    return null;
}
项目:allure-java    文件:AllureJunit5.java   
private List<Label> getTags(final TestIdentifier testIdentifier) {
    return testIdentifier.getTags().stream()
            .map(tag -> new Label().withName(TAG).withValue(tag.getName()))
            .collect(Collectors.toList());
}
项目:allure-java    文件:AllureJunit5.java   
protected String getHistoryId(final TestIdentifier testIdentifier) {
    return md5(testIdentifier.getUniqueId());
}
项目:junit5-extensions    文件:ExecutionReportListener.java   
@Override
public void executionSkipped(TestIdentifier testIdentifier, String reason) {
  executionReportBuilder.addSkipped(testIdentifier, reason);
}
项目:junit5-extensions    文件:ExecutionReportListener.java   
@Override
public void executionFinished(TestIdentifier testIdentifier,
    TestExecutionResult testExecutionResult) {
  executionReportBuilder.addResult(testIdentifier, testExecutionResult);
}
项目:pitest-junit5-plugin    文件:JUnit5TestUnit.java   
public JUnit5TestUnit(TestIdentifier testIdentifier) {
    super(TestIdentifiers.toDescription(testIdentifier));

    this.classLoaderDetection = IsolationUtils.loaderDetectionStrategy();
    this.testIdentifier = testIdentifier;
}
项目:verify-matching-service-adapter    文件:TestStatusPrintingListener.java   
@Override
public void testPlanExecutionFinished(TestPlan testPlan) {
    super.testPlanExecutionFinished(testPlan);
    long tests = testPlan.countTestIdentifiers(TestIdentifier::isTest);
    System.out.println("Test execution finished. Number of all tests: " + tests);
}
项目:verify-matching-service-adapter    文件:TestStatusPrintingListener.java   
private void printFailureMessage(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult, Color color) {
    if (testExecutionResult.getStatus().equals(Status.FAILED)) {
        testExecutionResult.getThrowable()
            .ifPresent(throwable -> printMessage(color, throwable.toString()));
    }
}
项目:jovial    文件:SerializingListener.java   
@Override
public void dynamicTestRegistered(TestIdentifier testIdentifier) {
    Map<String, Object> data = new HashMap<>();
    data.put("type", "dynamicTestRegistered");
    writeData(testIdentifier, data);
}
项目:jovial    文件:SerializingListener.java   
@Override
public void executionStarted(TestIdentifier testIdentifier) {
    Map<String, Object> data = new HashMap<>();
    data.put("type", "executionStarted");
    writeData(testIdentifier, data);
}