org.junit.platform.launcher.listeners.TestExecutionSummary Java Examples

The following examples show how to use org.junit.platform.launcher.listeners.TestExecutionSummary. 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: JunitPlatformDoer.java    From jeka with Apache License 2.0 6 votes vote down vote up
private static JkTestResult.JkFailure toFailure(TestExecutionSummary.Failure failure) {
    JkTestResult.JkTestIdentifier.JkType type;
    switch (failure.getTestIdentifier().getType()) {
        case CONTAINER:
            type = JkTestResult.JkTestIdentifier.JkType.CONTAINER;
            break;
        case CONTAINER_AND_TEST:
            type = JkTestResult.JkTestIdentifier.JkType.CONTAINER_AND_TEST;
            break;
        default:
            type = JkTestResult.JkTestIdentifier.JkType.TEST;
            break;
    }
    String testId = failure.getTestIdentifier().getUniqueId();
    String displayName = failure.getTestIdentifier().getDisplayName();
    Set<String> tags = failure.getTestIdentifier().getTags().stream().map(TestTag::toString)
            .collect(Collectors.toSet());
    JkTestResult.JkTestIdentifier id = JkTestResult.JkTestIdentifier.of(type, testId, displayName, tags);
    return JkTestResult.JkFailure.of(id, failure.getException().getMessage(),
            failure.getException().getStackTrace());
}
 
Example #2
Source File: JunitPlatformDoer.java    From jeka with Apache License 2.0 6 votes vote down vote up
private static JkTestResult toTestResult(TestExecutionSummary summary) {
    JkTestResult.JkCount containerCount = JkTestResult.JkCount.of(
            summary.getContainersFoundCount(),
            summary.getContainersStartedCount(),
            summary.getContainersSkippedCount(),
            summary.getContainersAbortedCount(),
            summary.getContainersSucceededCount(),
            summary.getContainersFailedCount());
    JkTestResult.JkCount testCount = JkTestResult.JkCount.of(
            summary.getTestsFoundCount(),
            summary.getTestsStartedCount(),
            summary.getTestsSkippedCount(),
            summary.getTestsAbortedCount(),
            summary.getTestsSucceededCount(),
            summary.getTestsFailedCount());
    List<JkTestResult.JkFailure> failures = summary.getFailures().stream()
            .map(JunitPlatformDoer::toFailure).collect(Collectors.toList());
    return JkTestResult.of(summary.getTimeStarted(), summary.getTimeFinished(),
            containerCount, testCount, failures);
}
 
Example #3
Source File: JunitRunner.java    From vespa with Apache License 2.0 6 votes vote down vote up
private String createJsonTestReport(TestExecutionSummary report, List<String> logLines) {
    var slime = new Slime();
    var root = slime.setObject();
    var summary = root.setObject("summary");
    summary.setLong("Total tests", report.getTestsFoundCount());
    summary.setLong("Test success", report.getTestsSucceededCount());
    summary.setLong("Test failed", report.getTestsFailedCount());
    summary.setLong("Test ignored", report.getTestsSkippedCount());
    summary.setLong("Test success", report.getTestsAbortedCount());
    summary.setLong("Test started", report.getTestsStartedCount());
    var failures = summary.setArray("failures");
    report.getFailures().forEach(failure -> serializeFailure(failure, failures.addObject()));

    var output = root.setArray("output");
    logLines.forEach(output::addString);

    return Exceptions.uncheck(() -> new String(SlimeUtils.toJsonBytes(slime), StandardCharsets.UTF_8));
}
 
Example #4
Source File: VertxExtensionTest.java    From vertx-junit5 with Apache License 2.0 6 votes vote down vote up
@Test
@DisplayName("⚙️ Check a timeout diagnosis")
void checkTimeoutFailureTestWithIntermediateAsyncVerifier() {
  LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(selectClass(EmbeddedWithARunner.TimingOut.class))
    .build();
  Launcher launcher = LauncherFactory.create();
  SummaryGeneratingListener listener = new SummaryGeneratingListener();
  launcher.registerTestExecutionListeners(listener);
  launcher.execute(request);
  TestExecutionSummary summary = listener.getSummary();
  assertThat(summary.getTestsStartedCount()).isEqualTo(1);
  assertThat(summary.getTestsFailedCount()).isEqualTo(1);
  Throwable exception = summary.getFailures().get(0).getException();
  assertThat(exception)
    .isInstanceOf(TimeoutException.class)
    .hasMessageContaining("checkpoint in file VertxExtensionTest.java");
}
 
Example #5
Source File: RunSellContractTests.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
public static void main(String[] args) {
    LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
            .selectors(
                    selectPackage("btdex.sellContract.dispute"),
                    selectClass(TestTakeRetake.class),
                    selectClass(TestInvalidTakeTake.class),
                    selectClass(TestInvalidTakeReopenWithdraw.class)
            )
            .build();

    Launcher launcher = LauncherFactory.create();
    // Register a listener
    SummaryGeneratingListener listener = new SummaryGeneratingListener();
    launcher.registerTestExecutionListeners(listener);

    //TestPlan testPlan = launcher.discover(request);

    launcher.execute(request);

    TestExecutionSummary summary = listener.getSummary();
    printReport(summary);


}
 
Example #6
Source File: RunSellContractTests.java    From btdex with GNU General Public License v3.0 6 votes vote down vote up
private static void printReport(TestExecutionSummary summary) {
    System.out.println(
            "\n------------------------------------------" +
                    "\nTests started: " + summary.getTestsStartedCount() +
                    "\nTests failed: " + summary.getTestsFailedCount() +
                    "\nTests succeeded: " + summary.getTestsSucceededCount() +
                    "\n------------------------------------------"
    );

    if(summary.getTestsFailedCount() > 0) {
        for(TestExecutionSummary.Failure f: summary.getFailures()){
            System.out.println(f.getTestIdentifier().getSource() +
                                "\nException " + f.getException());
        }
    }
}
 
Example #7
Source File: SummaryPrintingTestListener.java    From sbt-jupiter-interface with Apache License 2.0 6 votes vote down vote up
@Override
public void testPlanExecutionFinished(TestPlan testPlan) {

    TestExecutionSummary summary = getSummary();
    long testRunDuration = System.currentTimeMillis() - summary.getTimeStarted();

    long totalFailureCount = summary.getTotalFailureCount();
    long testsSkippedCount = summary.getTestsSkippedCount();
    long totalTestsFound = summary.getTestsFoundCount();

    Color ignoreColor = testsSkippedCount > 0 ? colorTheme.ignoreCount() : colorTheme.info();
    Color errorColor = totalFailureCount > 0 ? colorTheme.errorCount() : colorTheme.info();

    debugOrInfo(""
            + colorTheme.info().format("Test run finished: ")
            + errorColor.format(totalFailureCount + " failed")
            + colorTheme.info().format(", ")
            + ignoreColor.format(testsSkippedCount + " ignored")
            + colorTheme.info().format(", ")
            + colorTheme.info().format(totalTestsFound + " total, ")
            + colorTheme.info().format(testRunDuration/1000.0 + "s")
    );
}
 
Example #8
Source File: VertxExtensionTest.java    From vertx-junit5 with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("⚙️ Check a test failure")
void checkFailureTest() {
  LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(selectClass(FailureTest.class))
    .build();
  Launcher launcher = LauncherFactory.create();
  SummaryGeneratingListener listener = new SummaryGeneratingListener();
  launcher.registerTestExecutionListeners(listener);
  launcher.execute(request);
  TestExecutionSummary summary = listener.getSummary();
  assertThat(summary.getTestsStartedCount()).isEqualTo(1);
  assertThat(summary.getTestsFailedCount()).isEqualTo(1);
  assertThat(summary.getFailures().get(0).getException()).isInstanceOf(AssertionError.class);
}
 
Example #9
Source File: RunJUnit5TestsFromJava.java    From tutorials with MIT License 5 votes vote down vote up
public static void main(String[] args) {
    RunJUnit5TestsFromJava runner = new RunJUnit5TestsFromJava();
    runner.runAll();

    TestExecutionSummary summary = runner.listener.getSummary();
    summary.printTo(new PrintWriter(System.out));

    runner.runOne();

    summary = runner.listener.getSummary();
    summary.printTo(new PrintWriter(System.out));
}
 
Example #10
Source File: JupiterLoadProcessor.java    From zerocode with Apache License 2.0 5 votes vote down vote up
public void updatePassFailCount(SummaryGeneratingListener summaryListener) {
    TestExecutionSummary summary = summaryListener.getSummary();
    if (summary.getTotalFailureCount() > 0) {
        getFailedCounter().incrementAndGet();
        summary.getFailures().forEach(thisFailure -> {
            TestIdentifier testIdentifier = thisFailure.getTestIdentifier();
            String exceptionMessage = thisFailure.getException().getMessage();
            LOGGER.info("\n----------------------------------------------------------------------\n");
            LOGGER.info("\n###JUnit5: Test Failed Due To --> {}, \ntestIdentifier={}", exceptionMessage, testIdentifier);
            LOGGER.info("\n----------------------------------------------------------------------\n");
        });
    } else {
        getPassedCounter().incrementAndGet();
    }
}
 
Example #11
Source File: VertxExtensionTest.java    From vertx-junit5 with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("⚙️ Check a test failure with an intermediate async result verifier")
void checkFailureTestWithIntermediateAsyncVerifier() {
  LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(selectClass(FailureWithIntermediateAsyncVerifierTest.class))
    .build();
  Launcher launcher = LauncherFactory.create();
  SummaryGeneratingListener listener = new SummaryGeneratingListener();
  launcher.registerTestExecutionListeners(listener);
  launcher.execute(request);
  TestExecutionSummary summary = listener.getSummary();
  assertThat(summary.getTestsStartedCount()).isEqualTo(1);
  assertThat(summary.getTestsFailedCount()).isEqualTo(1);
  assertThat(summary.getFailures().get(0).getException()).isInstanceOf(AssertionError.class);
}
 
Example #12
Source File: VertxExtensionTest.java    From vertx-junit5 with Apache License 2.0 5 votes vote down vote up
@Test
@DisplayName("⚙️ Check a failure in the test method body rather than in a callback")
void checkDirectFailure() {
  LauncherDiscoveryRequest request = LauncherDiscoveryRequestBuilder.request()
    .selectors(selectClass(DirectFailureTest.class))
    .build();
  Launcher launcher = LauncherFactory.create();
  SummaryGeneratingListener listener = new SummaryGeneratingListener();
  launcher.registerTestExecutionListeners(listener);
  launcher.execute(request);
  TestExecutionSummary summary = listener.getSummary();
  assertThat(summary.getTestsStartedCount()).isEqualTo(1);
  assertThat(summary.getTestsFailedCount()).isEqualTo(1);
  assertThat(summary.getFailures().get(0).getException()).isInstanceOf(RuntimeException.class);
}
 
Example #13
Source File: FailingBeforeAndAfterMethodsSpringExtensionTests.java    From java-technology-stack with MIT License 5 votes vote down vote up
private void runTestAndAssertCounters(Class<?> testClass) {
	Launcher launcher = LauncherFactory.create();
	ExceptionTrackingListener listener = new ExceptionTrackingListener();
	launcher.registerTestExecutionListeners(listener);

	launcher.execute(request().selectors(selectClass(testClass)).build());
	TestExecutionSummary summary = listener.getSummary();

	String name = testClass.getSimpleName();
	int expectedStartedCount = getExpectedStartedCount(testClass);
	int expectedSucceededCount = getExpectedSucceededCount(testClass);
	int expectedFailedCount = getExpectedFailedCount(testClass);

	// @formatter:off
	assertAll(
		() -> assertEquals(1, summary.getTestsFoundCount(), () -> name + ": tests found"),
		() -> assertEquals(0, summary.getTestsSkippedCount(), () -> name + ": tests skipped"),
		() -> assertEquals(0, summary.getTestsAbortedCount(), () -> name + ": tests aborted"),
		() -> assertEquals(expectedStartedCount, summary.getTestsStartedCount(), () -> name + ": tests started"),
		() -> assertEquals(expectedSucceededCount, summary.getTestsSucceededCount(), () -> name + ": tests succeeded"),
		() -> assertEquals(expectedFailedCount, summary.getTestsFailedCount(), () -> name + ": tests failed")
	);
	// @formatter:on

	// Ensure it was an AssertionFailedError that failed the test and not
	// something else like an error in the @Configuration class, etc.
	if (expectedFailedCount > 0) {
		assertEquals(1, listener.exceptions.size(), "exceptions expected");
		Throwable exception = listener.exceptions.get(0);
		if (!(exception instanceof AssertionFailedError)) {
			throw new AssertionFailedError(
				exception.getClass().getName() + " is not an instance of " + AssertionFailedError.class.getName(),
				exception);
		}
	}
}
 
Example #14
Source File: FailingBeforeAndAfterMethodsSpringExtensionTests.java    From spring-analysis-note with MIT License 5 votes vote down vote up
private void runTestAndAssertCounters(Class<?> testClass) {
	Launcher launcher = LauncherFactory.create();
	ExceptionTrackingListener listener = new ExceptionTrackingListener();
	launcher.registerTestExecutionListeners(listener);

	launcher.execute(request().selectors(selectClass(testClass)).build());
	TestExecutionSummary summary = listener.getSummary();

	String name = testClass.getSimpleName();
	int expectedStartedCount = getExpectedStartedCount(testClass);
	int expectedSucceededCount = getExpectedSucceededCount(testClass);
	int expectedFailedCount = getExpectedFailedCount(testClass);

	// @formatter:off
	assertAll(
		() -> assertEquals(1, summary.getTestsFoundCount(), () -> name + ": tests found"),
		() -> assertEquals(0, summary.getTestsSkippedCount(), () -> name + ": tests skipped"),
		() -> assertEquals(0, summary.getTestsAbortedCount(), () -> name + ": tests aborted"),
		() -> assertEquals(expectedStartedCount, summary.getTestsStartedCount(), () -> name + ": tests started"),
		() -> assertEquals(expectedSucceededCount, summary.getTestsSucceededCount(), () -> name + ": tests succeeded"),
		() -> assertEquals(expectedFailedCount, summary.getTestsFailedCount(), () -> name + ": tests failed")
	);
	// @formatter:on

	// Ensure it was an AssertionFailedError that failed the test and not
	// something else like an error in the @Configuration class, etc.
	if (expectedFailedCount > 0) {
		assertEquals(1, listener.exceptions.size(), "exceptions expected");
		Throwable exception = listener.exceptions.get(0);
		if (!(exception instanceof AssertionFailedError)) {
			throw new AssertionFailedError(
				exception.getClass().getName() + " is not an instance of " + AssertionFailedError.class.getName(),
				exception);
		}
	}
}
 
Example #15
Source File: JUnit5TestRunner.java    From quickperf with Apache License 2.0 5 votes vote down vote up
private static TestExecutionSummary runTestMethod(Class<?> testClass, String methodName) {
    MethodSelector testMethodSelector = selectMethod(testClass, methodName);
    LauncherDiscoveryRequest request = request().selectors(testMethodSelector)
                                      .build();

    SummaryGeneratingListener listener = new SummaryGeneratingListener();

    Launcher launcher = LauncherFactory.create();
    launcher.execute(request, listener);

    return listener.getSummary();
}
 
Example #16
Source File: JUnit5Tests.java    From quickperf with Apache License 2.0 4 votes vote down vote up
public JUnit5TestsResult run()  {
    launcher.execute(request);
    TestExecutionSummary testExecutionSummary = listener.getSummary();
    return new JUnit5TestsResult(testExecutionSummary);
}
 
Example #17
Source File: TestRunner.java    From meghanada-server with GNU General Public License v3.0 4 votes vote down vote up
private void runJUnit(String arg, LauncherDiscoveryRequest request) {
  Stopwatch stopwatch = Stopwatch.createStarted();
  System.out.println(String.format("Running %s", arg));
  System.out.println();

  Launcher launcher = LauncherFactory.create();
  SummaryGeneratingListener listener = new SummaryGeneratingListener();
  launcher.execute(request, listener);
  TestExecutionSummary summary = listener.getSummary();
  this.runCnt += summary.getTestsFoundCount();
  this.failureCnt += summary.getTestsFailedCount();
  this.ignoreCnt += summary.getTestsSkippedCount();
  this.ignoreCnt += summary.getTestsSkippedCount();

  System.out.println();

  if (summary.getTestsFailedCount() > 0) {
    System.out.println(
        String.format(
            "FAIL Tests run: %d, Failures: %d, Ignore: %d, Time elapsed: %s",
            summary.getTestsFoundCount(),
            summary.getTestsFailedCount(),
            summary.getTestsSkippedCount(),
            stopwatch.stop()));
    System.out.println("Failures:");
    for (TestExecutionSummary.Failure failure : summary.getFailures()) {
      System.out.println(failure.getTestIdentifier().getDisplayName());
      failure.getException().printStackTrace();
      System.out.println();
    }
  } else {
    System.out.println(
        String.format(
            "Tests run: %d, Failures: %d, Ignore: %d, Time elapsed: %s",
            summary.getTestsFoundCount(),
            summary.getTestsFailedCount(),
            summary.getTestsSkippedCount(),
            stopwatch.stop()));
    System.out.println("Success");
  }

  System.out.println(Strings.repeat("-", 80));
}
 
Example #18
Source File: JUnit5TestRunner.java    From quickperf with Apache License 2.0 4 votes vote down vote up
private List<Throwable> convertToThrowables(List<TestExecutionSummary.Failure> failures) {
    return failures.stream()
                   .map(TestExecutionSummary.Failure::getException)
                   .collect(toList());
}
 
Example #19
Source File: JunitRunner.java    From vespa with Apache License 2.0 4 votes vote down vote up
private void serializeFailure(TestExecutionSummary.Failure failure, Cursor slime) {
    var testIdentifier = failure.getTestIdentifier();
    slime.setString("testName", testIdentifier.getUniqueId());
    slime.setString("testError",failure.getException().getMessage());
    slime.setString("exception", ExceptionUtils.getStackTraceAsString(failure.getException()));
}
 
Example #20
Source File: JUnit5Tests.java    From quickperf with Apache License 2.0 4 votes vote down vote up
public int getNumberOfFailures() {
    List<TestExecutionSummary.Failure> failures = testExecutionSummary.getFailures();
    return failures.size();
}
 
Example #21
Source File: JUnit5Tests.java    From quickperf with Apache License 2.0 4 votes vote down vote up
public JUnit5TestsResult(TestExecutionSummary testExecutionSummary) {
    this.testExecutionSummary = testExecutionSummary;
}
 
Example #22
Source File: JUnit5TestRunner.java    From quickperf with Apache License 2.0 3 votes vote down vote up
@Override
public TestIssue executeTestMethod(Class<?> testClass, String methodName) {
    TestExecutionSummary testResult = runTestMethod(testClass, methodName);

    List<TestExecutionSummary.Failure> failures = testResult.getFailures();

    List<Throwable> jUnit5failuresAsThrowables = convertToThrowables(failures);

    return TestIssue.buildInNewJvmFrom(jUnit5failuresAsThrowables);
}