Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring to focus implementation of the JUnit framework internals:
- Removed serializable objects for inter-process communication with tool-integrators - Supported different ways to generate test descriptors from configuration - Moved Console Launcher (main) to Sample Project - Introduced ReflectionUtils for common reflection tasks - Added TestListener interface with two implementations - Updated the Engine interface to work with TestDescriptors only
- Loading branch information
1 parent
4ed7da0
commit cbf9707
Showing
27 changed files
with
771 additions
and
666 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -74,5 +74,4 @@ configure(rootProject) { | |
task wrapper(type: Wrapper) { | ||
gradleVersion = '2.8' | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
junit-commons/src/main/java/org/junit/gen5/commons/util/ReflectionUtils.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,32 @@ | ||
package org.junit.gen5.commons.util; | ||
|
||
import java.lang.reflect.Constructor; | ||
import java.lang.reflect.InvocationTargetException; | ||
import java.lang.reflect.Method; | ||
|
||
/** | ||
* @author Stefan Bechtold | ||
* @since 5.0 | ||
*/ | ||
public class ReflectionUtils { | ||
private ReflectionUtils() { | ||
/* no-op */ | ||
} | ||
|
||
public static <T extends Object> T newInstance(Class<T> clazz) | ||
throws NoSuchMethodException, InstantiationException, IllegalAccessException, InvocationTargetException { | ||
Constructor<T> constructor = clazz.getDeclaredConstructor(); | ||
if (!constructor.isAccessible()) { | ||
constructor.setAccessible(true); | ||
} | ||
return constructor.newInstance(); | ||
} | ||
|
||
public static <T extends Object> T invokeMethod(Method method, Object testInstance) | ||
throws IllegalAccessException, InvocationTargetException { | ||
if (!method.isAccessible()) { | ||
method.setAccessible(true); | ||
} | ||
return (T) method.invoke(testInstance); | ||
} | ||
} |
148 changes: 86 additions & 62 deletions
148
junit-console/src/main/java/org/junit/gen5/console/ColoredPrintingTestListener.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 |
---|---|---|
@@ -1,72 +1,96 @@ | ||
package org.junit.gen5.console; | ||
|
||
import java.io.PrintStream; | ||
|
||
import org.junit.gen5.launcher.TestIdentifier; | ||
import org.junit.gen5.launcher.TestListener; | ||
import org.junit.gen5.engine.TestDescriptor; | ||
import org.junit.gen5.engine.TestListener; | ||
|
||
import java.io.PrintStream; | ||
|
||
/** | ||
* @author Stefan Bechtold | ||
* @since 5.0 | ||
*/ | ||
public class ColoredPrintingTestListener implements TestListener { | ||
public static final String ANSI_RESET = "\u001B[0m"; | ||
public static final String ANSI_BLACK = "\u001B[30m"; | ||
public static final String ANSI_RED = "\u001B[31m"; | ||
public static final String ANSI_GREEN = "\u001B[32m"; | ||
public static final String ANSI_YELLOW = "\u001B[33m"; | ||
public static final String ANSI_BLUE = "\u001B[34m"; | ||
public static final String ANSI_PURPLE = "\u001B[35m"; | ||
public static final String ANSI_CYAN = "\u001B[36m"; | ||
public static final String ANSI_WHITE = "\u001B[37m"; | ||
|
||
private final PrintStream out; | ||
|
||
public ColoredPrintingTestListener(PrintStream out) { | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public void testFound(TestIdentifier testIdentifier) { | ||
out.print(ANSI_GREEN); | ||
out.format("Test found: %s", testIdentifier.toString()); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testStarted(TestIdentifier testIdentifier) { | ||
out.print(ANSI_GREEN); | ||
out.format("Test started: %s", testIdentifier.toString()); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testSkipped(TestIdentifier testIdentifier, Throwable t) { | ||
out.print(ANSI_YELLOW); | ||
out.format("Test skipped: %s\n=> Exception: %s", testIdentifier.toString(), | ||
(t != null) ? t.getLocalizedMessage() : "none"); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testAborted(TestIdentifier testIdentifier, Throwable t) { | ||
out.print(ANSI_YELLOW); | ||
out.format("Test aborted: %s\n=> Exception: %s", testIdentifier.toString(), | ||
(t != null) ? t.getLocalizedMessage() : "none"); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testFailed(TestIdentifier testIdentifier, Throwable t) { | ||
out.print(ANSI_RED); | ||
out.format("Test failed: %s\n=> Exception: %s", testIdentifier.toString(), t.getLocalizedMessage()); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testSucceeded(TestIdentifier testIdentifier) { | ||
out.print(ANSI_GREEN); | ||
out.format("Test succeeded: %s", testIdentifier.toString()); | ||
out.println(ANSI_RESET); | ||
} | ||
public static final String ANSI_RESET = "\u001B[0m"; | ||
public static final String ANSI_BLACK = "\u001B[30m"; | ||
public static final String ANSI_RED = "\u001B[31m"; | ||
public static final String ANSI_GREEN = "\u001B[32m"; | ||
public static final String ANSI_YELLOW = "\u001B[33m"; | ||
public static final String ANSI_BLUE = "\u001B[34m"; | ||
public static final String ANSI_PURPLE = "\u001B[35m"; | ||
public static final String ANSI_CYAN = "\u001B[36m"; | ||
public static final String ANSI_WHITE = "\u001B[37m"; | ||
|
||
private final PrintStream out; | ||
|
||
public ColoredPrintingTestListener(PrintStream out) { | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public void testExecutionStarted() { | ||
out.println("Test execution started."); | ||
} | ||
|
||
@Override | ||
public void testExecutionPaused() { | ||
out.println("Test execution paused."); | ||
} | ||
|
||
@Override | ||
public void testExecutionRestarted() { | ||
out.println("Test execution continued."); | ||
} | ||
|
||
@Override | ||
public void testExecutionStopped() { | ||
out.println("Test execution canceled."); | ||
} | ||
|
||
@Override | ||
public void testExecutionFinished() { | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testFound(TestDescriptor testDescriptor) { | ||
out.print(ANSI_GREEN); | ||
out.format("Test found: %s", testDescriptor.toString()); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testStarted(TestDescriptor testDescriptor) { | ||
out.print(ANSI_GREEN); | ||
out.format("Test started: %s", testDescriptor.toString()); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testSkipped(TestDescriptor testDescriptor, Throwable t) { | ||
out.print(ANSI_YELLOW); | ||
out.format("Test skipped: %s\n=> Exception: %s", testDescriptor.toString(), (t != null) ? t.getLocalizedMessage() : "none"); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testAborted(TestDescriptor testDescriptor, Throwable t) { | ||
out.print(ANSI_YELLOW); | ||
out.format("Test aborted: %s\n=> Exception: %s", testDescriptor.toString(), (t != null) ? t.getLocalizedMessage() : "none"); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testFailed(TestDescriptor testDescriptor, Throwable t) { | ||
out.print(ANSI_RED); | ||
out.format("Test failed: %s\n=> Exception: %s", testDescriptor.toString(), t.getLocalizedMessage()); | ||
out.println(ANSI_RESET); | ||
} | ||
|
||
@Override | ||
public void testSucceeded(TestDescriptor testDescriptor) { | ||
out.print(ANSI_GREEN); | ||
out.format("Test succeeded: %s", testDescriptor.toString()); | ||
out.println(ANSI_RESET); | ||
} | ||
} |
29 changes: 0 additions & 29 deletions
29
junit-console/src/main/java/org/junit/gen5/console/Console.java
This file was deleted.
Oops, something went wrong.
149 changes: 93 additions & 56 deletions
149
junit-console/src/main/java/org/junit/gen5/console/TestSummaryReportingTestListener.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 |
---|---|---|
@@ -1,66 +1,103 @@ | ||
package org.junit.gen5.console; | ||
|
||
import java.io.PrintStream; | ||
import org.junit.gen5.engine.TestDescriptor; | ||
import org.junit.gen5.engine.TestListener; | ||
|
||
import org.junit.gen5.launcher.TestIdentifier; | ||
import org.junit.gen5.launcher.TestListener; | ||
import java.io.PrintStream; | ||
|
||
/** | ||
* @author Stefan Bechtold | ||
* @since 5.0 | ||
*/ | ||
public class TestSummaryReportingTestListener implements TestListener { | ||
private final PrintStream out; | ||
|
||
int testsFound; | ||
int testsSkipped; | ||
int testsAborted; | ||
int testsSucceeded; | ||
int testsFailed; | ||
|
||
private long timeStarted; | ||
private long timePaused; | ||
private long timeFinished; | ||
|
||
public TestSummaryReportingTestListener(PrintStream out) { | ||
this.out = out; | ||
} | ||
|
||
private void reportSummary(String msg) { | ||
timeFinished = System.currentTimeMillis(); | ||
|
||
out.println(String.format( | ||
"%s after %d ms\n" + "[%10d tests found ]\n" + "[%10d tests skipped ]\n" | ||
+ "[%10d tests aborted ]\n" + "[%10d tests failed ]\n" + "[%10d tests successful]\n", | ||
msg, timeFinished - timeStarted, testsFound, testsSkipped, testsAborted, testsFailed, testsSucceeded)); | ||
} | ||
|
||
@Override | ||
public void testFound(TestIdentifier testIdentifier) { | ||
testsFound++; | ||
} | ||
|
||
@Override | ||
public void testStarted(TestIdentifier testIdentifier) { | ||
} | ||
|
||
@Override | ||
public void testSkipped(TestIdentifier testIdentifier, Throwable t) { | ||
testsSkipped++; | ||
} | ||
|
||
@Override | ||
public void testAborted(TestIdentifier testIdentifier, Throwable t) { | ||
testsAborted++; | ||
} | ||
|
||
@Override | ||
public void testFailed(TestIdentifier testIdentifier, Throwable t) { | ||
testsFailed++; | ||
} | ||
|
||
@Override | ||
public void testSucceeded(TestIdentifier testIdentifier) { | ||
testsSucceeded++; | ||
} | ||
private final PrintStream out; | ||
|
||
int testsFound; | ||
int testsSkipped; | ||
int testsAborted; | ||
int testsSucceeded; | ||
int testsFailed; | ||
|
||
private long timeStarted; | ||
private long timePaused; | ||
private long timeFinished; | ||
|
||
public TestSummaryReportingTestListener(PrintStream out) { | ||
this.out = out; | ||
} | ||
|
||
@Override | ||
public void testExecutionStarted() { | ||
timeStarted = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public void testExecutionPaused() { | ||
timePaused = System.currentTimeMillis(); | ||
} | ||
|
||
@Override | ||
public void testExecutionRestarted() { | ||
timeStarted += System.currentTimeMillis() - timePaused; | ||
timePaused = 0; | ||
} | ||
|
||
@Override | ||
public void testExecutionStopped() { | ||
reportSummary("Test run stopped"); | ||
} | ||
|
||
@Override | ||
public void testExecutionFinished() { | ||
reportSummary("Test run finished"); | ||
} | ||
|
||
private void reportSummary(String msg) { | ||
timeFinished = System.currentTimeMillis(); | ||
|
||
out.println(String.format( | ||
"%s after %d ms\n" + | ||
"[%10d tests found ]\n" + | ||
"[%10d tests skipped ]\n" + | ||
"[%10d tests aborted ]\n" + | ||
"[%10d tests failed ]\n" + | ||
"[%10d tests successful]\n", | ||
msg, | ||
timeFinished - timeStarted, | ||
testsFound, | ||
testsSkipped, | ||
testsAborted, | ||
testsFailed, | ||
testsSucceeded | ||
)); | ||
} | ||
|
||
@Override | ||
public void testFound(TestDescriptor testDescriptor) { | ||
testsFound++; | ||
} | ||
|
||
@Override | ||
public void testStarted(TestDescriptor testDescriptor) { | ||
} | ||
|
||
@Override | ||
public void testSkipped(TestDescriptor testDescriptor, Throwable t) { | ||
testsSkipped++; | ||
} | ||
|
||
@Override | ||
public void testAborted(TestDescriptor testDescriptor, Throwable t) { | ||
testsAborted++; | ||
} | ||
|
||
@Override | ||
public void testFailed(TestDescriptor testDescriptor, Throwable t) { | ||
testsFailed++; | ||
} | ||
|
||
@Override | ||
public void testSucceeded(TestDescriptor testDescriptor) { | ||
testsSucceeded++; | ||
} | ||
} |
Oops, something went wrong.