Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted summary creating listener from console runner for reuse
- Loading branch information
Showing
4 changed files
with
207 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
123 changes: 0 additions & 123 deletions
123
junit-console/src/main/java/org/junit/gen5/console/TestSummaryReportingTestListener.java
This file was deleted.
Oops, something went wrong.
92 changes: 92 additions & 0 deletions
92
...launcher/src/main/java/org/junit/gen5/launcher/listeners/SummaryCreatingTestListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.junit.gen5.launcher.listeners; | ||
|
||
import java.io.PrintStream; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import org.junit.gen5.engine.TestDescriptor; | ||
import org.junit.gen5.engine.TestExecutionListener; | ||
import org.junit.gen5.launcher.TestPlan; | ||
import org.junit.gen5.launcher.TestPlanExecutionListener; | ||
|
||
/** | ||
* @author Stefan Bechtold | ||
* @author Sam Brannen | ||
* @since 5.0 | ||
*/ | ||
public class SummaryCreatingTestListener implements TestPlanExecutionListener, TestExecutionListener { | ||
|
||
private final TestExecutionSummary summary; | ||
|
||
public SummaryCreatingTestListener(TestExecutionSummary summary) { | ||
this.summary = summary; | ||
} | ||
|
||
@Override | ||
public void testPlanExecutionStarted(TestPlan testPlan) { | ||
summary.testsFound.set(testPlan.countStaticTests()); | ||
summary.timeStarted = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public void testPlanExecutionPaused(TestPlan testPlan) { | ||
summary.timePaused = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public void testPlanExecutionRestarted(TestPlan testPlan) { | ||
summary.timeStarted += System.currentTimeMillis() - summary.timePaused; | ||
summary.timePaused = 0; | ||
} | ||
|
||
@Override | ||
public void testPlanExecutionStopped(TestPlan testPlan) { | ||
summary.finishTestRun("Test run stopped"); | ||
} | ||
|
||
@Override | ||
public void testPlanExecutionFinished(TestPlan testPlan) { | ||
summary.finishTestRun("Test run finished"); | ||
} | ||
|
||
@Override | ||
public void dynamicTestFound(TestDescriptor testDescriptor) { | ||
summary.testsFound.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void testStarted(TestDescriptor testDescriptor) { | ||
summary.testsStarted.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void testSkipped(TestDescriptor testDescriptor, Throwable t) { | ||
summary.testsSkipped.addAndGet(testDescriptor.countStaticTests()); | ||
} | ||
|
||
@Override | ||
public void testAborted(TestDescriptor testDescriptor, Throwable t) { | ||
summary.testsAborted.incrementAndGet(); | ||
} | ||
|
||
@Override | ||
public void testFailed(TestDescriptor testDescriptor, Throwable t) { | ||
summary.testsFailed.incrementAndGet(); | ||
summary.addFailure(testDescriptor, t); | ||
} | ||
|
||
@Override | ||
public void testSucceeded(TestDescriptor testDescriptor) { | ||
summary.testsSucceeded.incrementAndGet(); | ||
} | ||
|
||
} |
85 changes: 85 additions & 0 deletions
85
junit-launcher/src/main/java/org/junit/gen5/launcher/listeners/TestExecutionSummary.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.junit.gen5.launcher.listeners; | ||
|
||
import java.io.PrintWriter; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.StringJoiner; | ||
import java.util.concurrent.ExecutionException; | ||
import java.util.concurrent.Future; | ||
import java.util.concurrent.TimeUnit; | ||
import java.util.concurrent.TimeoutException; | ||
import java.util.concurrent.atomic.AtomicLong; | ||
|
||
import lombok.Value; | ||
|
||
import org.junit.gen5.engine.TestDescriptor; | ||
|
||
// TODO Give it a REAL interface and make it threadsafe | ||
public class TestExecutionSummary { | ||
|
||
final AtomicLong testsStarted = new AtomicLong(); | ||
final AtomicLong testsFound = new AtomicLong(); | ||
final AtomicLong testsSkipped = new AtomicLong(); | ||
final AtomicLong testsAborted = new AtomicLong(); | ||
final AtomicLong testsSucceeded = new AtomicLong(); | ||
final AtomicLong testsFailed = new AtomicLong(); | ||
|
||
long timeStarted; | ||
long timePaused; | ||
long timeFinished; | ||
|
||
private String message; | ||
private List<Failure> failures = new ArrayList<>(); | ||
|
||
void finishTestRun(String message) { | ||
this.timeFinished = System.currentTimeMillis(); | ||
this.message = message; | ||
} | ||
|
||
public void printOn(PrintWriter writer) { | ||
|
||
// @formatter:off | ||
writer.println(String.format( | ||
"%n%s after %d ms\n" | ||
+ "[%10d tests found ]\n" | ||
+ "[%10d tests started ]\n" | ||
+ "[%10d tests skipped ]\n" | ||
+ "[%10d tests aborted ]\n" | ||
+ "[%10d tests successful]\n" | ||
+ "[%10d tests failed ]\n", | ||
this.message, (this.timeFinished - this.timeStarted), this.testsFound.get(), this.testsStarted.get(), | ||
this.testsSkipped.get(), this.testsAborted.get(), this.testsSucceeded.get(), this.testsFailed.get())); | ||
// @formatter:on | ||
|
||
// if (countFailedTests() > 0) { | ||
// writer.println("Test failures: "); | ||
// } | ||
|
||
writer.flush(); | ||
} | ||
|
||
public long countFailedTests() { | ||
return testsFailed.get(); | ||
} | ||
|
||
public void addFailure(TestDescriptor testDescriptor, Throwable throwable) { | ||
failures.add(new Failure(testDescriptor, throwable)); | ||
} | ||
|
||
@Value | ||
static class Failure { | ||
|
||
final private TestDescriptor descriptor; | ||
final private Throwable exception; | ||
} | ||
} |