Skip to content

Commit

Permalink
Rename JUnit5 Runner to JUnitPlatform
Browse files Browse the repository at this point in the history
Issue: #286
  • Loading branch information
sbrannen committed Jun 17, 2016
1 parent 4a1be0c commit f4eca58
Show file tree
Hide file tree
Showing 25 changed files with 87 additions and 77 deletions.
2 changes: 1 addition & 1 deletion documentation/src/docs/asciidoc/index.adoc
Expand Up @@ -32,7 +32,7 @@ Stefan Bechtold; Sam Brannen; Johannes Link; Matthias Merdes; Marc Philipp
:ExtendWith: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/ExtendWith.java[@ExtendWith] :ExtendWith: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/ExtendWith.java[@ExtendWith]
:ExtensionRegistrar: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/ExtensionRegistrar.java[ExtensionRegistrar] :ExtensionRegistrar: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/ExtensionRegistrar.java[ExtensionRegistrar]
:TestInstancePostProcessor: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/TestInstancePostProcessor.java[TestInstancePostProcessor] :TestInstancePostProcessor: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/TestInstancePostProcessor.java[TestInstancePostProcessor]
:JUnit5-Runner: {master-branch}/junit4-runner/src/main/java/org/junit/gen5/junit4/runner/JUnit5.java[JUnit5] :JUnitPlatform-Runner: {master-branch}/junit4-runner/src/main/java/org/junit/gen5/junit4/runner/JUnitPlatform.java[JUnitPlatform]
:ParameterResolver: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/ParameterResolver.java[ParameterResolver] :ParameterResolver: {master-branch}/junit5-api/src/main/java/org/junit/gen5/api/extension/ParameterResolver.java[ParameterResolver]
:MockitoExtension: {junit5-samples-repo}/blob/master/junit5-mockito-extension/src/main/java/com/example/mockito/MockitoExtension.java[MockitoExtension] :MockitoExtension: {junit5-samples-repo}/blob/master/junit5-mockito-extension/src/main/java/com/example/mockito/MockitoExtension.java[MockitoExtension]
:SpringExtension: https://github.com/sbrannen/spring-test-junit5/blob/master/src/main/java/org/springframework/test/context/junit5/SpringExtension.java[SpringExtension] :SpringExtension: https://github.com/sbrannen/spring-test-junit5/blob/master/src/main/java/org/springframework/test/context/junit5/SpringExtension.java[SpringExtension]
Expand Down
33 changes: 20 additions & 13 deletions documentation/src/docs/asciidoc/running-tests.adoc
Expand Up @@ -272,11 +272,17 @@ Option Description
[[running-tests-junit4-runner]] [[running-tests-junit4-runner]]
=== Using JUnit 4 to Run JUnit 5 Tests === Using JUnit 4 to Run JUnit 5 Tests


The `JUnit5` runner lets you run JUnit 5 tests with JUnit 4. This way you can run JUnit 5 The `JUnitPlatform` runner is a JUnit 4 based `Runner` which enables you to run any test
tests in IDEs and build tools that only know about JUnit 4. As soon as we add reporting whose programming model is supported on the JUnit Platform in a JUnit 4 environment --
features to JUnit 5 that JUnit 4 does not have, the runner will only be able to support a for example, a JUnit 5 test class.
subset of the JUnit 5 functionality. But for the time being the `JUnit5` runner is an
easy way to get started. Annotating a class with `@RunWith(JUnitPlatform.class)` allows it to be run with IDEs and
build systems that support JUnit 4 but do not yet support the JUnit Platform directly.

Since the JUnit Platform has features that JUnit 4 does not have, the runner is only able
to support a subset of the JUnit Platform functionality, especially with regard to
reporting. But for the time being the `JUnitPlatform` runner is an easy way to get
started.


==== Setup ==== Setup


Expand All @@ -285,16 +291,16 @@ You need the following artifacts and their dependencies on the classpath. See
versions. versions.


* `junit5-api` in _test_ scope: API for writing tests, including `@Test`, etc. * `junit5-api` in _test_ scope: API for writing tests, including `@Test`, etc.
* `junit4-runner` in _test_ scope: location of the `JUnit5` runner * `junit4-runner` in _test_ scope: location of the `JUnitPlatform` runner
* `junit5-engine` in _test runtime_ scope: implementation of the Engine API for JUnit 5 * `junit5-engine` in _test runtime_ scope: implementation of the Engine API for JUnit 5


==== Single Test Class ==== Single Test Class


One way to use the `JUnit5` runner is to annotate a JUnit 5 test class with One way to use the `JUnitPlatform` runner is to annotate a test class with
`@RunWith(JUnit5.class)` directly. Please note that the test methods are annotated with `@RunWith(JUnitPlatform.class)` directly. Please note that the test methods in the
`org.junit.gen5.api.Test` (JUnit 5), not `org.junit.Test` (JUnit 4). Moreover, in this following example are annotated with `org.junit.gen5.api.Test` (JUnit 5), not
case the test class must be `public` because; otherwise, the IDEs won't recognize it as a `org.junit.Test` (JUnit 4). Moreover, in this case the test class must be `public`;
test class. otherwise, IDEs won't recognize it as a test class.


[source,java,indent=0] [source,java,indent=0]
[subs="verbatim"] [subs="verbatim"]
Expand All @@ -304,7 +310,8 @@ include::{testDir}/example/JUnit4ClassDemo.java[tags=user_guide]


==== Test Suite ==== Test Suite


If you have multiple JUnit 5 test classes you can create a test suite. If you have multiple test classes you can create a test suite as can be seen in the
following example.


[source,java,indent=0] [source,java,indent=0]
[subs="verbatim"] [subs="verbatim"]
Expand All @@ -318,4 +325,4 @@ and its subpackages.
There are more configuration options for discovering and filtering tests than just There are more configuration options for discovering and filtering tests than just
`@Packages`. Please consult the `@Packages`. Please consult the
{javadoc-root}/org/junit/gen5/junit4/runner/package-summary.html[Javadoc] or the source {javadoc-root}/org/junit/gen5/junit4/runner/package-summary.html[Javadoc] or the source
code for the `{JUnit5-Runner}` runner for further details. code for the `{JUnitPlatform-Runner}` runner for further details.
2 changes: 1 addition & 1 deletion documentation/src/docs/asciidoc/writing-tests.adoc
Expand Up @@ -189,7 +189,7 @@ include::{testDir}/example/TestInfoDemo.java[tags=user_guide]
+ +
In JUnit 5 you should use `TestReporter` where In JUnit 5 you should use `TestReporter` where
you used to print information to `stdout` or `stderr` in JUnit 4. you used to print information to `stdout` or `stderr` in JUnit 4.
Using `@RunWith(JUnit5.class)` will even output all reported entries to `stdout`. Using `@RunWith(JUnitPlatform.class)` will even output all reported entries to `stdout`.


[source,java,indent=0] [source,java,indent=0]
[subs="verbatim"] [subs="verbatim"]
Expand Down
Expand Up @@ -12,7 +12,7 @@


import org.junit.gen5.junit4.runner.ExcludeTags; import org.junit.gen5.junit4.runner.ExcludeTags;
import org.junit.gen5.junit4.runner.FilterClassName; import org.junit.gen5.junit4.runner.FilterClassName;
import org.junit.gen5.junit4.runner.JUnit5; import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages; import org.junit.gen5.junit4.runner.Packages;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


Expand All @@ -29,7 +29,7 @@
* *
* @since 5.0 * @since 5.0
*/ */
@RunWith(JUnit5.class) @RunWith(JUnitPlatform.class)
@Packages("example") @Packages("example")
@FilterClassName(".+(Tests|Demo)$") @FilterClassName(".+(Tests|Demo)$")
@ExcludeTags("exclude") @ExcludeTags("exclude")
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/JUnit4ClassDemo.java
Expand Up @@ -14,10 +14,10 @@
import static org.junit.gen5.api.Assertions.fail; import static org.junit.gen5.api.Assertions.fail;


import org.junit.gen5.api.Test; import org.junit.gen5.api.Test;
import org.junit.gen5.junit4.runner.JUnit5; import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


@RunWith(JUnit5.class) @RunWith(JUnitPlatform.class)
public class JUnit4ClassDemo { public class JUnit4ClassDemo {


@Test @Test
Expand Down
4 changes: 2 additions & 2 deletions documentation/src/test/java/example/JUnit4SuiteDemo.java
Expand Up @@ -11,11 +11,11 @@
package example; package example;


//tag::user_guide[] //tag::user_guide[]
import org.junit.gen5.junit4.runner.JUnit5; import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages; import org.junit.gen5.junit4.runner.Packages;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


@RunWith(JUnit5.class) @RunWith(JUnitPlatform.class)
@Packages("example") @Packages("example")
//end::user_guide[] //end::user_guide[]
@org.junit.gen5.junit4.runner.ExcludeTags("exclude") @org.junit.gen5.junit4.runner.ExcludeTags("exclude")
Expand Down
Expand Up @@ -13,7 +13,7 @@
import org.junit.gen5.engine.junit5.JUnit5TestEngine; import org.junit.gen5.engine.junit5.JUnit5TestEngine;
import org.junit.gen5.junit4.runner.FilterClassName; import org.junit.gen5.junit4.runner.FilterClassName;
import org.junit.gen5.junit4.runner.IncludeEngines; import org.junit.gen5.junit4.runner.IncludeEngines;
import org.junit.gen5.junit4.runner.JUnit5; import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.gen5.junit4.runner.Packages; import org.junit.gen5.junit4.runner.Packages;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


Expand All @@ -32,7 +32,7 @@
* *
* @since 5.0 * @since 5.0
*/ */
@RunWith(JUnit5.class) @RunWith(JUnitPlatform.class)
@Packages("org.junit.gen5") @Packages("org.junit.gen5")
@FilterClassName(".*Tests?") @FilterClassName(".*Tests?")
@IncludeEngines(JUnit5TestEngine.ENGINE_ID) @IncludeEngines(JUnit5TestEngine.ENGINE_ID)
Expand Down
Expand Up @@ -31,13 +31,13 @@
import joptsimple.OptionException; import joptsimple.OptionException;


import org.junit.gen5.api.Test; import org.junit.gen5.api.Test;
import org.junit.gen5.junit4.runner.JUnit5; import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


/** /**
* @since 5.0 * @since 5.0
*/ */
@RunWith(JUnit5.class) @RunWith(JUnitPlatform.class)
public class JOptSimpleCommandLineOptionsParserTests { public class JOptSimpleCommandLineOptionsParserTests {


@Test @Test
Expand Down
Expand Up @@ -64,7 +64,7 @@
import org.junit.gen5.engine.junit4.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichIsIgnored; import org.junit.gen5.engine.junit4.samples.junit4.PlainJUnit4TestCaseWithSingleTestWhichIsIgnored;
import org.junit.gen5.engine.junit4.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods; import org.junit.gen5.engine.junit4.samples.junit4.PlainJUnit4TestCaseWithTwoTestMethods;
import org.junit.gen5.engine.junit4.samples.junit4.SingleFailingTheoryTestCase; import org.junit.gen5.engine.junit4.samples.junit4.SingleFailingTheoryTestCase;
import org.junit.gen5.engine.junit4.samples.junit4.TestCaseRunWithJUnit5; import org.junit.gen5.engine.junit4.samples.junit4.TestCaseRunWithJUnitPlatformRunner;
import org.junit.gen5.engine.support.descriptor.JavaClassSource; import org.junit.gen5.engine.support.descriptor.JavaClassSource;
import org.junit.gen5.engine.support.descriptor.JavaMethodSource; import org.junit.gen5.engine.support.descriptor.JavaMethodSource;
import org.junit.gen5.launcher.TestDiscoveryRequest; import org.junit.gen5.launcher.TestDiscoveryRequest;
Expand Down Expand Up @@ -201,8 +201,8 @@ void doesNotResolvePlainOldJavaClassesWithoutAnyTest() {
} }


@Test @Test
void doesNotResolveClassRunWithJUnit5() { void doesNotResolveClassRunWithJUnitPlatform() {
assertYieldsNoDescriptors(TestCaseRunWithJUnit5.class); assertYieldsNoDescriptors(TestCaseRunWithJUnitPlatformRunner.class);
} }


@Test @Test
Expand Down
Expand Up @@ -11,13 +11,13 @@
package org.junit.gen5.engine.junit4.samples.junit4; package org.junit.gen5.engine.junit4.samples.junit4;


import org.junit.gen5.junit4.runner.Classes; import org.junit.gen5.junit4.runner.Classes;
import org.junit.gen5.junit4.runner.JUnit5; import org.junit.gen5.junit4.runner.JUnitPlatform;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;


/** /**
* @since 5.0 * @since 5.0
*/ */
@RunWith(JUnit5.class) @RunWith(JUnitPlatform.class)
@Classes(PlainJUnit4TestCaseWithSingleTestWhichFails.class) @Classes(PlainJUnit4TestCaseWithSingleTestWhichFails.class)
public class TestCaseRunWithJUnit5 { public class TestCaseRunWithJUnitPlatformRunner {
} }
Expand Up @@ -66,11 +66,11 @@
import org.mockito.InOrder; import org.mockito.InOrder;


/** /**
* Tests for the {@link JUnit5} runner. * Tests for the {@link JUnitPlatform} runner.
* *
* @since 5.0 * @since 5.0
*/ */
class JUnit5RunnerTests { class JUnitPlatformRunnerTests {


@Nested @Nested
class Discovery { class Discovery {
Expand Down Expand Up @@ -234,7 +234,7 @@ void convertsTestIdentifiersIntoDescriptions() throws Exception {
Launcher launcher = mock(Launcher.class); Launcher launcher = mock(Launcher.class);
when(launcher.discover(any())).thenReturn(testPlan); when(launcher.discover(any())).thenReturn(testPlan);


JUnit5 runner = new JUnit5(TestClass.class, launcher); JUnitPlatform runner = new JUnitPlatform(TestClass.class, launcher);


Description runnerDescription = runner.getDescription(); Description runnerDescription = runner.getDescription();
assertEquals(createSuiteDescription(TestClass.class), runnerDescription); assertEquals(createSuiteDescription(TestClass.class), runnerDescription);
Expand Down Expand Up @@ -276,7 +276,7 @@ void appliesFilter() throws Exception {
ArgumentCaptor<TestDiscoveryRequest> captor = ArgumentCaptor.forClass(TestDiscoveryRequest.class); ArgumentCaptor<TestDiscoveryRequest> captor = ArgumentCaptor.forClass(TestDiscoveryRequest.class);
when(launcher.discover(captor.capture())).thenReturn(fullTestPlan).thenReturn(filteredTestPlan); when(launcher.discover(captor.capture())).thenReturn(fullTestPlan).thenReturn(filteredTestPlan);


JUnit5 runner = new JUnit5(TestClass.class, launcher); JUnitPlatform runner = new JUnitPlatform(TestClass.class, launcher);
runner.filter(matchMethodDescription(testDescription("[root:leaf2b]"))); runner.filter(matchMethodDescription(testDescription("[root:leaf2b]")));


TestDiscoveryRequest lastDiscoveryRequest = captor.getValue(); TestDiscoveryRequest lastDiscoveryRequest = captor.getValue();
Expand All @@ -297,7 +297,7 @@ void throwsNoTestsRemainExceptionWhenNoTestIdentifierMatchesFilter() throws Exce
Launcher launcher = mock(Launcher.class); Launcher launcher = mock(Launcher.class);
when(launcher.discover(any())).thenReturn(testPlan); when(launcher.discover(any())).thenReturn(testPlan);


JUnit5 runner = new JUnit5(TestClass.class, launcher); JUnitPlatform runner = new JUnitPlatform(TestClass.class, launcher);


assertThrows(NoTestsRemainException.class, assertThrows(NoTestsRemainException.class,
() -> runner.filter(matchMethodDescription(suiteDescription("[root:doesNotExist]")))); () -> runner.filter(matchMethodDescription(suiteDescription("[root:doesNotExist]"))));
Expand All @@ -321,7 +321,7 @@ void notifiesRunListenerOfTestExecution() throws Exception {


RunNotifier notifier = new RunNotifier(); RunNotifier notifier = new RunNotifier();
notifier.addListener(runListener); notifier.addListener(runListener);
new JUnit5(TestClass.class, createLauncher(engine)).run(notifier); new JUnitPlatform(TestClass.class, createLauncher(engine)).run(notifier);


InOrder inOrder = inOrder(runListener); InOrder inOrder = inOrder(runListener);


Expand Down Expand Up @@ -365,7 +365,7 @@ void reportsIgnoredEventsForLeafsWhenContainerIsSkipped() throws Exception {


RunNotifier notifier = new RunNotifier(); RunNotifier notifier = new RunNotifier();
notifier.addListener(runListener); notifier.addListener(runListener);
new JUnit5(TestClass.class, createLauncher(engine)).run(notifier); new JUnitPlatform(TestClass.class, createLauncher(engine)).run(notifier);


verify(runListener).testIgnored(testDescription("[root:leaf]")); verify(runListener).testIgnored(testDescription("[root:leaf]"));
verifyNoMoreInteractions(runListener); verifyNoMoreInteractions(runListener);
Expand Down Expand Up @@ -393,7 +393,7 @@ private TestDiscoveryRequest instantiateRunnerAndCaptureGeneratedRequest(Class<?
ArgumentCaptor<TestDiscoveryRequest> captor = ArgumentCaptor.forClass(TestDiscoveryRequest.class); ArgumentCaptor<TestDiscoveryRequest> captor = ArgumentCaptor.forClass(TestDiscoveryRequest.class);
when(launcher.discover(captor.capture())).thenReturn(TestPlan.from(emptySet())); when(launcher.discover(captor.capture())).thenReturn(TestPlan.from(emptySet()));


new JUnit5(testClass, launcher); new JUnitPlatform(testClass, launcher);


return captor.getValue(); return captor.getValue();
} }
Expand Down
Expand Up @@ -52,7 +52,7 @@ protected JUnit4Builder junit4Builder() {


/** /**
* Customization of {@link AnnotatedBuilder} that ignores classes annotated * Customization of {@link AnnotatedBuilder} that ignores classes annotated
* with {@code @RunWith(JUnit5.class)} to avoid infinite recursion. * with {@code @RunWith(JUnitPlatform.class)} to avoid infinite recursion.
*/ */
private static class DefensiveAnnotatedBuilder extends AnnotatedBuilder { private static class DefensiveAnnotatedBuilder extends AnnotatedBuilder {


Expand All @@ -63,7 +63,7 @@ public DefensiveAnnotatedBuilder(RunnerBuilder suiteBuilder) {
@Override @Override
public Runner buildRunner(Class<? extends Runner> runnerClass, Class<?> testClass) throws Exception { public Runner buildRunner(Class<? extends Runner> runnerClass, Class<?> testClass) throws Exception {
// Referenced by name because it might not be available at runtime. // Referenced by name because it might not be available at runtime.
if ("org.junit.gen5.junit4.runner.JUnit5".equals(runnerClass.getName())) { if ("org.junit.gen5.junit4.runner.JUnitPlatform".equals(runnerClass.getName())) {
return null; return null;
} }
return super.buildRunner(runnerClass, testClass); return super.buildRunner(runnerClass, testClass);
Expand Down
Expand Up @@ -23,7 +23,7 @@


/** /**
* {@code @Classes} specifies the test classes to be run when a class * {@code @Classes} specifies the test classes to be run when a class
* annotated with {@code @RunWith(JUnit5.class)} is run. * annotated with {@code @RunWith(JUnitPlatform.class)} is run.
* *
* @since 5.0 * @since 5.0
*/ */
Expand Down
Expand Up @@ -24,7 +24,8 @@
/** /**
* {@code @ExcludeEngines} specifies the {@linkplain #value IDs} of * {@code @ExcludeEngines} specifies the {@linkplain #value IDs} of
* {@link org.junit.gen5.engine.TestEngine TestEngines} to be excluded from the * {@link org.junit.gen5.engine.TestEngine TestEngines} to be excluded from the
* test plan when a class annotated with {@code @RunWith(JUnit5.class)} is run. * test plan when a class annotated with {@code @RunWith(JUnitPlatform.class)}
* is run.
* *
* @since 5.0 * @since 5.0
* @see IncludeEngines * @see IncludeEngines
Expand Down
Expand Up @@ -23,7 +23,7 @@


/** /**
* {@code @ExcludeTags} specifies the {@linkplain #value tags} to be excluded * {@code @ExcludeTags} specifies the {@linkplain #value tags} to be excluded
* from the test plan when a class annotated with {@code @RunWith(JUnit5.class)} * from the test plan when a class annotated with {@code @RunWith(JUnitPlatform.class)}
* is run. * is run.
* *
* @since 5.0 * @since 5.0
Expand Down
Expand Up @@ -22,9 +22,9 @@
import org.junit.gen5.commons.meta.API; import org.junit.gen5.commons.meta.API;


/** /**
* {@code @FilterClassName} specifies a regular expression that is used * {@code @FilterClassName} specifies a regular expression that is used to
* to match against fully qualified class names * match against fully qualified class names when a test class annotated with
* when a test class annotated with {@code @RunWith(JUnit5.class)} is executed. * {@code @RunWith(JUnitPlatform.class)} is run.
* *
* @since 5.0 * @since 5.0
*/ */
Expand Down
Expand Up @@ -24,7 +24,8 @@
/** /**
* {@code @IncludeEngines} specifies the {@linkplain #value IDs} of * {@code @IncludeEngines} specifies the {@linkplain #value IDs} of
* {@link org.junit.gen5.engine.TestEngine TestEngines} to be included in the * {@link org.junit.gen5.engine.TestEngine TestEngines} to be included in the
* test plan when a class annotated with {@code @RunWith(JUnit5.class)} is run. * test plan when a class annotated with {@code @RunWith(JUnitPlatform.class)}
* is run.
* *
* @since 5.0 * @since 5.0
* @see ExcludeEngines * @see ExcludeEngines
Expand Down
Expand Up @@ -23,7 +23,7 @@


/** /**
* {@code @IncludeTags} specifies the {@linkplain #value tags} to be included * {@code @IncludeTags} specifies the {@linkplain #value tags} to be included
* in the test plan when a class annotated with {@code @RunWith(JUnit5.class)} * in the test plan when a class annotated with {@code @RunWith(JUnitPlatform.class)}
* is run. * is run.
* *
* @since 5.0 * @since 5.0
Expand Down

0 comments on commit f4eca58

Please sign in to comment.