Java 类org.junit.platform.engine.TestExecutionResult 实例源码

项目: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());
  }
}
项目:junit-pioneer    文件:TestIntegrationTests.java   
@org.junit.jupiter.api.Test
void testWithExpectedException_successfulTest_fails() {
    ExecutionEventRecorder eventRecorder = executeTests(TestTestCase.class,
        "testWithExpectedException_successfulTest");

    assertThat(eventRecorder.getTestStartedCount()).isEqualTo(1);
    assertThat(eventRecorder.getTestFailedCount()).isEqualTo(1);

    //@formatter:off
    Optional<String> failedTestMessage = eventRecorder
            .getFailedTestFinishedEvents().get(0)
            .getPayload(TestExecutionResult.class)
            .flatMap(TestExecutionResult::getThrowable)
            .map(Throwable::getMessage);
    //@formatter:on
    String expectedMessage = format(EXPECTED_EXCEPTION_WAS_NOT_THROWN, IllegalArgumentException.class);
    assertThat(failedTestMessage).contains(expectedMessage);
}
项目:junit-pioneer    文件:TestIntegrationTests.java   
@org.junit.jupiter.api.Test
void testWithExpectedException_exceptionThrownOfSupertype_fails() {
    ExecutionEventRecorder eventRecorder = executeTests(TestTestCase.class,
        "testWithExpectedException_exceptionThrownOfSupertype");

    assertThat(eventRecorder.getTestStartedCount()).isEqualTo(1);
    assertThat(eventRecorder.getTestFailedCount()).isEqualTo(1);

    //@formatter:off
    Optional<Throwable> failedTestThrowable = eventRecorder
            .getFailedTestFinishedEvents().get(0)
            .getPayload(TestExecutionResult.class)
            .flatMap(TestExecutionResult::getThrowable);
    //@formatter:on
    assertThat(failedTestThrowable).containsInstanceOf(RuntimeException.class);
}
项目:junit-pioneer    文件:TestIntegrationTests.java   
@org.junit.jupiter.api.Test
void testWithTimeout_exceedsTimeout_fails() throws Exception {
    ExecutionEventRecorder eventRecorder = executeTests(TestTestCase.class, "testWithTimeout_exceedsTimeout");

    assertThat(eventRecorder.getTestStartedCount()).isEqualTo(1);
    assertThat(eventRecorder.getTestFailedCount()).isEqualTo(1);

    //@formatter:off
    Optional<String> failedTestMessage = eventRecorder
            .getFailedTestFinishedEvents().get(0)
            .getPayload(TestExecutionResult.class)
            .flatMap(TestExecutionResult::getThrowable)
            .map(Throwable::getMessage);
    String expectedMessage = String.format(
            TimeoutExtension.TEST_RAN_TOO_LONG, "testWithTimeout_exceedsTimeout()", 1, 10);
    //@formatter:on
    // the message contains the actual run time, which is unpredictable, so it has to be cut off for the assertion
    String expectedKnownPrefix = expectedMessage.substring(0, expectedMessage.length() - 6);
    assertThat(failedTestMessage).isNotEmpty();
    assertThat(failedTestMessage.get()).startsWith(expectedKnownPrefix);
}
项目: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);
    }
}
项目: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();
    }
}
项目:webtester2-core    文件:TestClassExecutor.java   
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) {
    Optional<Throwable> throwable = testExecutionResult.getThrowable();
    if (throwable.isPresent()) {
        throw new UndeclaredThrowableException(throwable.get());
    }
}
项目: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);
}
项目:junit5-samples    文件:Machine.java   
@Override
public void execute(ExecutionRequest request) {
    TestDescriptor engine = request.getRootTestDescriptor();
    EngineExecutionListener listener = request.getEngineExecutionListener();
    listener.executionStarted(engine);
    for (TestDescriptor child : engine.getChildren()) {
        listener.executionStarted(child);
        listener.executionFinished(child, TestExecutionResult.successful());
    }
    listener.executionFinished(engine, TestExecutionResult.successful());
}
项目:junit5-extensions    文件:ExecutionReportListener.java   
@Override
public void executionFinished(TestIdentifier testIdentifier,
    TestExecutionResult testExecutionResult) {
  executionReportBuilder.addResult(testIdentifier, testExecutionResult);
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult result) {
  addEvent(ExecutionEvent.executionFinished(testDescriptor, result));
}
项目:junit-extensions    文件:RecordingExecutionListener.java   
public Stream<ExecutionEvent> getFinishedEventsByStatus(Status status) {
  return getEventsByType(FINISHED)
      .filter(
          byPayload(
              TestExecutionResult.class, where(TestExecutionResult::getStatus, isEqual(status))));
}
项目:junit-extensions    文件:ExecutionEvent.java   
public static ExecutionEvent executionFinished(
    TestDescriptor testDescriptor, TestExecutionResult result) {
  return new ExecutionEvent(FINISHED, testDescriptor, result);
}
项目: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()));
    }
}
项目:junit5-docker    文件:JupiterExecutionListener.java   
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult testExecutionResult) {
    allTestsPassed = allTestsPassed && testExecutionResult.getStatus() == SUCCESSFUL;
}
项目:junit-pioneer    文件:ExecutionEvent.java   
public static ExecutionEvent executionFinished(TestDescriptor testDescriptor, TestExecutionResult result) {
    return new ExecutionEvent(FINISHED, testDescriptor, result);
}
项目:junit-pioneer    文件:TestExecutionResultConditions.java   
public static Condition<TestExecutionResult> status(Status expectedStatus) {
    return new Condition<>(where(TestExecutionResult::getStatus, isEqual(expectedStatus)), "status is %s",
        expectedStatus);
}
项目:junit-pioneer    文件:TestExecutionResultConditions.java   
public static Condition<TestExecutionResult> cause(Condition<? super Throwable> condition) {
    return new Condition<TestExecutionResult>(where(TestExecutionResult::getThrowable, throwable -> {
        return throwable.isPresent() && condition.matches(throwable.get());
    }), "cause where %s", condition);
}
项目:junit-pioneer    文件:ExecutionEventConditions.java   
public static Condition<ExecutionEvent> finished(Condition<TestExecutionResult> resultCondition) {
    return allOf(type(FINISHED), result(resultCondition));
}
项目:junit-pioneer    文件:ExecutionEventConditions.java   
public static Condition<ExecutionEvent> result(Condition<TestExecutionResult> condition) {
    return new Condition<>(byPayload(TestExecutionResult.class, condition::matches), "event with result where %s",
        condition);
}
项目:junit-pioneer    文件:ExecutionEventRecorder.java   
@Override
public void executionFinished(TestDescriptor testDescriptor, TestExecutionResult result) {
    addEvent(ExecutionEvent.executionFinished(testDescriptor, result));
}
项目:junit-pioneer    文件:ExecutionEventRecorder.java   
private Stream<ExecutionEvent> testFinishedEvents(Status status) {
    return testEventsByType(FINISHED).filter(
        byPayload(TestExecutionResult.class, where(TestExecutionResult::getStatus, isEqual(status))));
}