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 ====== 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 * The `selectMethod(String)` method in `DiscoverySelectors` now supports selection of
a _fully qualified method name_ for a method that accepts parameters -- for example: a _fully qualified method name_ for a method that accepts parameters -- for example:
`"org.example.TestClass#testMethod(org.junit.jupiter.api.TestInfo)"`. `"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 :junitPlatformTest
Test run finished after 93 ms Test run finished after 93 ms
[ 3 tests found ] [ 3 containers found ]
[ 1 tests skipped ] [ 0 containers skipped ]
[ 2 tests started ] [ 3 containers started ]
[ 0 tests aborted ] [ 0 containers aborted ]
[ 2 tests successful ] [ 3 containers successful ]
[ 0 tests failed ] [ 0 containers failed ]
[ 0 containers failed] [ 3 tests found ]
[ 1 tests skipped ]
[ 2 tests started ]
[ 0 tests aborted ]
[ 2 tests successful ]
[ 0 tests failed ]
BUILD SUCCESSFUL BUILD SUCCESSFUL
---- ----
Expand All @@ -160,13 +165,18 @@ Test failures (1):
=> Exception: 2 is not equal to 1 ==> expected: <2> but was: <1> => Exception: 2 is not equal to 1 ==> expected: <2> but was: <1>
Test run finished after 99 ms Test run finished after 99 ms
[ 3 tests found ] [ 3 containers found ]
[ 0 tests skipped ] [ 0 containers skipped ]
[ 3 tests started ] [ 3 containers started ]
[ 0 tests aborted ] [ 0 containers aborted ]
[ 2 tests successful ] [ 3 containers successful ]
[ 1 tests failed ] [ 0 containers failed ]
[ 0 containers failed] [ 3 tests found ]
[ 0 tests skipped ]
[ 3 tests started ]
[ 0 tests aborted ]
[ 2 tests successful ]
[ 1 tests failed ]
:junitPlatformTest FAILED :junitPlatformTest FAILED
Expand Down Expand Up @@ -236,13 +246,18 @@ Engine finished: junit-jupiter
Test execution finished. Test execution finished.
Test run finished after 29 ms Test run finished after 29 ms
[ 2 tests found ] [ 2 containers found ]
[ 1 tests started ] [ 0 containers skipped ]
[ 1 tests skipped ] [ 2 containers started ]
[ 0 tests aborted ] [ 0 containers aborted ]
[ 1 tests successful ] [ 2 containers successful ]
[ 0 tests failed ] [ 0 containers failed ]
[ 0 containers failed] [ 2 tests found ]
[ 1 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
---- ----


.Exit Code .Exit Code
Expand Down
Expand Up @@ -30,13 +30,19 @@ class MutableTestExecutionSummary implements TestExecutionSummary {
private static final String TAB = " "; private static final String TAB = " ";
private static final String DOUBLE_TAB = TAB + 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 testsFound = new AtomicLong();
final AtomicLong testsStarted = new AtomicLong(); final AtomicLong testsStarted = new AtomicLong();
final AtomicLong testsSkipped = new AtomicLong(); final AtomicLong testsSkipped = new AtomicLong();
final AtomicLong testsAborted = new AtomicLong(); final AtomicLong testsAborted = new AtomicLong();
final AtomicLong testsSucceeded = new AtomicLong(); final AtomicLong testsSucceeded = new AtomicLong();
final AtomicLong testsFailed = new AtomicLong(); final AtomicLong testsFailed = new AtomicLong();
final AtomicLong containersFailed = new AtomicLong();


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


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


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


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


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


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


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


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

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

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


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


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


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


@Override @Override
public long getTimeFinished() { public long getTestsSkippedCount() {
return this.timeFinished; 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 @Override
public void printTo(PrintWriter writer) { public void printTo(PrintWriter writer) {
// @formatter:off // @formatter:off
writer.println(String.format( writer.println(String.format(
"%nTest run finished after %d ms%n" "%nTest run finished after %d ms%n"
+ "[%10d tests found ]%n"
+ "[%10d tests skipped ]%n" + "[%10d containers found ]%n"
+ "[%10d tests started ]%n" + "[%10d containers skipped ]%n"
+ "[%10d tests aborted ]%n" + "[%10d containers started ]%n"
+ "[%10d tests successful ]%n" + "[%10d containers aborted ]%n"
+ "[%10d tests failed ]%n" + "[%10d containers successful ]%n"
+ "[%10d containers failed]%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.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.testsFound.get(),
this.testsSkipped.get(), this.testsSkipped.get(),
this.testsStarted.get(), this.testsStarted.get(),
this.testsAborted.get(), this.testsAborted.get(),
this.testsSucceeded.get(), this.testsSucceeded.get(),
this.testsFailed.get(), this.testsFailed.get()
this.containersFailed.get()
)); ));
// @formatter:on // @formatter:on


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


import static java.util.stream.Stream.concat; import static java.util.stream.Stream.concat;
import static org.junit.platform.commons.meta.API.Usage.Experimental; 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 java.util.stream.Stream;


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


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


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


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


@Override @Override
public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) { public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult testExecutionResult) {
if (testExecutionResult.getStatus() == SUCCESSFUL) {
if (testIdentifier.isTest()) { switch (testExecutionResult.getStatus()) {
this.summary.testsSucceeded.incrementAndGet();
} case SUCCESSFUL: {
} if (testIdentifier.isContainer()) {
else if (testExecutionResult.getStatus() == ABORTED) { this.summary.containersSucceeded.incrementAndGet();
if (testIdentifier.isTest()) { }
this.summary.testsAborted.incrementAndGet(); if (testIdentifier.isTest()) {
this.summary.testsSucceeded.incrementAndGet();
}
break;
} }
}
else if (testExecutionResult.getStatus() == FAILED) { case ABORTED: {
if (testIdentifier.isTest()) { if (testIdentifier.isContainer()) {
this.summary.testsFailed.incrementAndGet(); 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.