Skip to content

Commit

Permalink
Support all container events in TestExecutionSummary
Browse files Browse the repository at this point in the history
The `TestExecutionSummary` used by the `ConsoleLauncher` and the JUnit
Platform Gradle plugin now includes statistics for all container events.

Closes: #420
  • Loading branch information
sbrannen committed Aug 8, 2016
1 parent 7cf9dbb commit 7e14f94
Show file tree
Hide file tree
Showing 6 changed files with 292 additions and 117 deletions.
2 changes: 2 additions & 0 deletions documentation/src/docs/asciidoc/release-notes-5.0.0-M3.adoc
Expand Up @@ -29,6 +29,8 @@ on GitHub.

====== New Features

* The `TestExecutionSummary` used by the `ConsoleLauncher` and the JUnit Platform Gradle
plugin now includes statistics for all container events.
* The `selectMethod(String)` method in `DiscoverySelectors` now supports selection of
a _fully qualified method name_ for a method that accepts parameters -- for example:
`"org.example.TestClass#testMethod(org.junit.jupiter.api.TestInfo)"`.
Expand Down
57 changes: 36 additions & 21 deletions documentation/src/docs/asciidoc/running-tests.adoc
Expand Up @@ -137,13 +137,18 @@ in output similar to the following:
:junitPlatformTest
Test run finished after 93 ms
[ 3 tests found ]
[ 1 tests skipped ]
[ 2 tests started ]
[ 0 tests aborted ]
[ 2 tests successful ]
[ 0 tests failed ]
[ 0 containers failed]
[ 3 containers found ]
[ 0 containers skipped ]
[ 3 containers started ]
[ 0 containers aborted ]
[ 3 containers successful ]
[ 0 containers failed ]
[ 3 tests found ]
[ 1 tests skipped ]
[ 2 tests started ]
[ 0 tests aborted ]
[ 2 tests successful ]
[ 0 tests failed ]
BUILD SUCCESSFUL
----
Expand All @@ -160,13 +165,18 @@ Test failures (1):
=> Exception: 2 is not equal to 1 ==> expected: <2> but was: <1>
Test run finished after 99 ms
[ 3 tests found ]
[ 0 tests skipped ]
[ 3 tests started ]
[ 0 tests aborted ]
[ 2 tests successful ]
[ 1 tests failed ]
[ 0 containers failed]
[ 3 containers found ]
[ 0 containers skipped ]
[ 3 containers started ]
[ 0 containers aborted ]
[ 3 containers successful ]
[ 0 containers failed ]
[ 3 tests found ]
[ 0 tests skipped ]
[ 3 tests started ]
[ 0 tests aborted ]
[ 2 tests successful ]
[ 1 tests failed ]
:junitPlatformTest FAILED
Expand Down Expand Up @@ -236,13 +246,18 @@ Engine finished: junit-jupiter
Test execution finished.
Test run finished after 29 ms
[ 2 tests found ]
[ 1 tests started ]
[ 1 tests skipped ]
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
[ 0 containers failed]
[ 2 containers found ]
[ 0 containers skipped ]
[ 2 containers started ]
[ 0 containers aborted ]
[ 2 containers successful ]
[ 0 containers failed ]
[ 2 tests found ]
[ 1 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
----

.Exit Code
Expand Down
Expand Up @@ -30,13 +30,19 @@ class MutableTestExecutionSummary implements TestExecutionSummary {
private static final String TAB = " ";
private static final String DOUBLE_TAB = TAB + TAB;

final AtomicLong containersFound = new AtomicLong();
final AtomicLong containersStarted = new AtomicLong();
final AtomicLong containersSkipped = new AtomicLong();
final AtomicLong containersAborted = new AtomicLong();
final AtomicLong containersSucceeded = new AtomicLong();
final AtomicLong containersFailed = new AtomicLong();

final AtomicLong testsFound = new AtomicLong();
final AtomicLong testsStarted = new AtomicLong();
final AtomicLong testsSkipped = new AtomicLong();
final AtomicLong testsAborted = new AtomicLong();
final AtomicLong testsSucceeded = new AtomicLong();
final AtomicLong testsFailed = new AtomicLong();
final AtomicLong containersFailed = new AtomicLong();

private final TestPlan testPlan;
private final List<Failure> failures = new ArrayList<>();
Expand All @@ -45,6 +51,7 @@ class MutableTestExecutionSummary implements TestExecutionSummary {

MutableTestExecutionSummary(TestPlan testPlan) {
this.testPlan = testPlan;
this.containersFound.set(testPlan.countTestIdentifiers(TestIdentifier::isContainer));
this.testsFound.set(testPlan.countTestIdentifiers(TestIdentifier::isTest));
this.timeStarted = System.currentTimeMillis();
}
Expand All @@ -54,33 +61,43 @@ void addFailure(TestIdentifier testIdentifier, Throwable throwable) {
}

@Override
public long getTestsFoundCount() {
return this.testsFound.get();
public long getTimeStarted() {
return this.timeStarted;
}

@Override
public long getTestsStartedCount() {
return this.testsStarted.get();
public long getTimeFinished() {
return this.timeFinished;
}

@Override
public long getTestsSkippedCount() {
return this.testsSkipped.get();
public long getTotalFailureCount() {
return getTestsFailedCount() + getContainersFailedCount();
}

@Override
public long getTestsAbortedCount() {
return this.testsAborted.get();
public long getContainersFoundCount() {
return this.containersFound.get();
}

@Override
public long getTestsSucceededCount() {
return this.testsSucceeded.get();
public long getContainersStartedCount() {
return this.containersStarted.get();
}

@Override
public long getTestsFailedCount() {
return this.testsFailed.get();
public long getContainersSkippedCount() {
return this.containersSkipped.get();
}

@Override
public long getContainersAbortedCount() {
return this.containersAborted.get();
}

@Override
public long getContainersSucceededCount() {
return this.containersSucceeded.get();
}

@Override
Expand All @@ -89,40 +106,70 @@ public long getContainersFailedCount() {
}

@Override
public long getTotalFailureCount() {
return getTestsFailedCount() + getContainersFailedCount();
public long getTestsFoundCount() {
return this.testsFound.get();
}

@Override
public long getTimeStarted() {
return this.timeStarted;
public long getTestsStartedCount() {
return this.testsStarted.get();
}

@Override
public long getTimeFinished() {
return this.timeFinished;
public long getTestsSkippedCount() {
return this.testsSkipped.get();
}

@Override
public long getTestsAbortedCount() {
return this.testsAborted.get();
}

@Override
public long getTestsSucceededCount() {
return this.testsSucceeded.get();
}

@Override
public long getTestsFailedCount() {
return this.testsFailed.get();
}

@Override
public void printTo(PrintWriter writer) {
// @formatter:off
writer.println(String.format(
"%nTest run finished after %d ms%n"
+ "[%10d tests found ]%n"
+ "[%10d tests skipped ]%n"
+ "[%10d tests started ]%n"
+ "[%10d tests aborted ]%n"
+ "[%10d tests successful ]%n"
+ "[%10d tests failed ]%n"
+ "[%10d containers failed]%n",

+ "[%10d containers found ]%n"
+ "[%10d containers skipped ]%n"
+ "[%10d containers started ]%n"
+ "[%10d containers aborted ]%n"
+ "[%10d containers successful ]%n"
+ "[%10d containers failed ]%n"

+ "[%10d tests found ]%n"
+ "[%10d tests skipped ]%n"
+ "[%10d tests started ]%n"
+ "[%10d tests aborted ]%n"
+ "[%10d tests successful ]%n"
+ "[%10d tests failed ]%n",

(this.timeFinished - this.timeStarted),

this.containersFound.get(),
this.containersSkipped.get(),
this.containersStarted.get(),
this.containersAborted.get(),
this.containersSucceeded.get(),
this.containersFailed.get(),

this.testsFound.get(),
this.testsSkipped.get(),
this.testsStarted.get(),
this.testsAborted.get(),
this.testsSucceeded.get(),
this.testsFailed.get(),
this.containersFailed.get()
this.testsFailed.get()
));
// @formatter:on

Expand Down
Expand Up @@ -12,13 +12,11 @@

import static java.util.stream.Stream.concat;
import static org.junit.platform.commons.meta.API.Usage.Experimental;
import static org.junit.platform.engine.TestExecutionResult.Status.ABORTED;
import static org.junit.platform.engine.TestExecutionResult.Status.FAILED;
import static org.junit.platform.engine.TestExecutionResult.Status.SUCCESSFUL;

import java.util.stream.Stream;

import org.junit.platform.commons.meta.API;
import org.junit.platform.commons.util.PreconditionViolationException;
import org.junit.platform.engine.TestExecutionResult;
import org.junit.platform.launcher.TestExecutionListener;
import org.junit.platform.launcher.TestIdentifier;
Expand Down Expand Up @@ -57,47 +55,78 @@ public void testPlanExecutionFinished(TestPlan testPlan) {

@Override
public void dynamicTestRegistered(TestIdentifier testIdentifier) {
this.summary.testsFound.incrementAndGet();
if (testIdentifier.isContainer()) {
this.summary.containersFound.incrementAndGet();
}
if (testIdentifier.isTest()) {
this.summary.testsFound.incrementAndGet();
}
}

@Override
public void executionSkipped(TestIdentifier testIdentifier, String reason) {
// @formatter:off
long skippedContainers = concat(Stream.of(testIdentifier), testPlan.getDescendants(testIdentifier).stream())
.filter(TestIdentifier::isContainer)
.count();
long skippedTests = concat(Stream.of(testIdentifier), testPlan.getDescendants(testIdentifier).stream())
.filter(TestIdentifier::isTest)
.count();
// @formatter:on
this.summary.containersSkipped.addAndGet(skippedContainers);
this.summary.testsSkipped.addAndGet(skippedTests);
}

@Override
public void executionStarted(TestIdentifier testIdentifier) {
if (testIdentifier.isContainer()) {
this.summary.containersStarted.incrementAndGet();
}
if (testIdentifier.isTest()) {
this.summary.testsStarted.incrementAndGet();
}
}

@Override
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
if (testExecutionResult.getStatus() == SUCCESSFUL) {
if (testIdentifier.isTest()) {
this.summary.testsSucceeded.incrementAndGet();
}
}
else if (testExecutionResult.getStatus() == ABORTED) {
if (testIdentifier.isTest()) {
this.summary.testsAborted.incrementAndGet();

switch (testExecutionResult.getStatus()) {

case SUCCESSFUL: {
if (testIdentifier.isContainer()) {
this.summary.containersSucceeded.incrementAndGet();
}
if (testIdentifier.isTest()) {
this.summary.testsSucceeded.incrementAndGet();
}
break;
}
}
else if (testExecutionResult.getStatus() == FAILED) {
if (testIdentifier.isTest()) {
this.summary.testsFailed.incrementAndGet();

case ABORTED: {
if (testIdentifier.isContainer()) {
this.summary.containersAborted.incrementAndGet();
}
if (testIdentifier.isTest()) {
this.summary.testsAborted.incrementAndGet();
}
break;
}
else if (testIdentifier.isContainer()) {
this.summary.containersFailed.incrementAndGet();

case FAILED: {
if (testIdentifier.isContainer()) {
this.summary.containersFailed.incrementAndGet();
}
if (testIdentifier.isTest()) {
this.summary.testsFailed.incrementAndGet();
}
testExecutionResult.getThrowable().ifPresent(
throwable -> this.summary.addFailure(testIdentifier, throwable));
break;
}
testExecutionResult.getThrowable().ifPresent(
throwable -> this.summary.addFailure(testIdentifier, throwable));

default:
throw new PreconditionViolationException(
"Unsupported execution status:" + testExecutionResult.getStatus());
}
}

Expand Down

0 comments on commit 7e14f94

Please sign in to comment.