-
Notifications
You must be signed in to change notification settings - Fork 542
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Donate current sources from junit-platform-surefire-provider #184
Merged
+3,916
−107
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
200 changes: 200 additions & 0 deletions
200
maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm
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,200 @@ | ||
------ | ||
Using JUnit 5 Platform | ||
------ | ||
JUnit Lambda Team <[email protected]> | ||
------ | ||
2018-05-14 | ||
------ | ||
|
||
~~ Licensed to the Apache Software Foundation (ASF) under one | ||
~~ or more contributor license agreements. See the NOTICE file | ||
~~ distributed with this work for additional information | ||
~~ regarding copyright ownership. The ASF licenses this file | ||
~~ to you under the Apache License, Version 2.0 (the | ||
~~ "License"); you may not use this file except in compliance | ||
~~ with the License. You may obtain a copy of the License at | ||
~~ | ||
~~ http://www.apache.org/licenses/LICENSE-2.0 | ||
~~ | ||
~~ Unless required by applicable law or agreed to in writing, | ||
~~ software distributed under the License is distributed on an | ||
~~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
~~ KIND, either express or implied. See the License for the | ||
~~ specific language governing permissions and limitations | ||
~~ under the License. | ||
|
||
~~ NOTE: For help with the syntax of this file, see: | ||
~~ http://maven.apache.org/doxia/references/apt-format.html | ||
|
||
Using JUnit 5 Platform | ||
|
||
* Configuring JUnit Platform | ||
|
||
To get started with JUnit Platform, you need to add at least a single <<<TestEngine>>> implementation | ||
to your project. For example, if you want to write tests with Jupiter, add the test artifact | ||
<<<junit-jupiter-engine>>> to the dependencies in POM: | ||
|
||
+---+ | ||
<dependencies> | ||
[...] | ||
<dependency> | ||
<groupId>org.junit.jupiter</groupId> | ||
<artifactId>junit-jupiter-engine</artifactId> | ||
<version>5.2.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
[...] | ||
</dependencies> | ||
+---+ | ||
|
||
This will pull in all required dependencies. Among those dependencies is <<<junit-jupiter-api>>> which contains | ||
the classes and interfaces your test source requires to compile. <<<junit-platform-engine>>> is also resolved and | ||
added. | ||
|
||
This is the only step that is required to get started - you can now create tests in your test source directory | ||
(e.g., <<<src/test/java>>>). | ||
|
||
If you want to write and execute JUnit 3 or 4 tests via the JUnit Platform add the Vintage Engine to the | ||
dependencies: | ||
|
||
+---+ | ||
<dependencies> | ||
[...] | ||
<dependency> | ||
<groupId>org.junit.vintage</groupId> | ||
<artifactId>junit-vintage-engine</artifactId> | ||
<version>5.2.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
[...] | ||
</dependencies> | ||
+---+ | ||
|
||
* Provider Selection | ||
|
||
If nothing is configured, Surefire detects which JUnit version to use by the following algorithm: | ||
|
||
+---+ | ||
if the JUnit 5 Platform Engine is present in the project | ||
use junit-platform | ||
if the JUnit version in the project >= 4.7 and the <<<parallel>>> configuration parameter has ANY value | ||
use junit47 provider | ||
if JUnit >= 4.0 is present | ||
use junit4 provider | ||
else | ||
use junit3.8.1 | ||
+---+ | ||
|
||
When using this technique there is no check that the proper test-frameworks are present on your project's | ||
classpath. Failing to add the proper test-frameworks will result in a build failure. | ||
|
||
* Running Tests in Parallel | ||
|
||
From JUnit Platform does not support running tests in parallel. | ||
|
||
* Running a Single Test Class | ||
|
||
The JUnit Platform Provider supports the <<<test>>> JVM system property supported by | ||
the Maven Surefire Plugin. For example, to run only test methods in the <<<org.example.MyTest>>> test class | ||
you can execute <<<mvn -Dtest=org.example.MyTest test>>> from the command line. | ||
|
||
|
||
* Filtering by Test Class Names | ||
|
||
The Maven Surefire Plugin will scan for test classes whose fully qualified names match | ||
the following patterns. | ||
|
||
* <<<**/Test*.java>>> | ||
|
||
* <<<**/*Test.java>>> | ||
|
||
* <<<**/*Tests.java>>> | ||
|
||
* <<<**/*TestCase.java>>> | ||
|
||
Moreover, it will exclude all nested classes (including static member classes) by default. | ||
|
||
Note, however, that you can override this default behavior by configuring explicit | ||
`include` and `exclude` rules in your `pom.xml` file. For example, to keep Maven Surefire | ||
from excluding static member classes, you can override its exclude rules. | ||
|
||
* Overriding exclude rules of Maven Surefire | ||
|
||
+---+ | ||
... | ||
<build> | ||
<plugins> | ||
... | ||
<plugin> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${project.artifactId}</artifactId> | ||
<version>${project.version}</version> | ||
<configuration> | ||
<excludes> | ||
<exclude>some test to exclude here</exclude> | ||
</excludes> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
+---+ | ||
|
||
|
||
* Filtering by Tags | ||
|
||
You can use JUnit5 Tags and filter tests by tags or tag expressions. | ||
|
||
* to include <<<tags>>> or <<<tag expressions>>>, use <<<groups>>>. | ||
|
||
* to exclude <<<tags>>> or <<<tag expressions>>>, use either <<<excludedGroups>>>. | ||
|
||
+---+ | ||
... | ||
<build> | ||
<plugins> | ||
... | ||
<plugin> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${project.artifactId}</artifactId> | ||
<version>${project.version}</version> | ||
<configuration> | ||
<groups>acceptance | !feature-a</groups> | ||
<excludedGroups>integration, regression</excludedGroups> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
+---+ | ||
|
||
|
||
* Configuration Parameters | ||
|
||
You can set JUnit Platform configuration parameters to influence test discovery and execution by | ||
declaring the <<<configurationParameters>>> property and providing key-value pairs using the Java | ||
<<<Properties>>> file syntax (as shown below) or via the <<<junit-platform.properties>>> file. | ||
|
||
+---+ | ||
... | ||
<build> | ||
<plugins> | ||
... | ||
<plugin> | ||
<groupId>${project.groupId}</groupId> | ||
<artifactId>${project.artifactId}</artifactId> | ||
<version>${project.version}</version> | ||
<configuration> | ||
<properties> | ||
<configurationParameters> | ||
junit.jupiter.conditions.deactivate = * | ||
junit.jupiter.extensions.autodetection.enabled = true | ||
junit.jupiter.testinstance.lifecycle.default = per_class | ||
</configurationParameters> | ||
</properties> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
... | ||
+---+ |
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
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here the order of provider-info was changed. Does it mean something important for functionality?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are the built-in providers documented somewhere? I couldn't find any external information.
The first auto-detected provider wins, right?
If I understand the
isApplicable()
logic correctly, theplatform
info needs to checked before the legacy JUnit (3 + 4) infos. This is due to fact, that a legacy "junit-4.12.jar" is present in both cases: the users is on 4 and wants to run JUnit 4 test cases. Or the user is on "5" and wants to Vintage Engine to execute JUnit 4 or 3 test cases.So, when we find
org.junit.platform:junit-platform-engine
as a dependency the uses wants to launch the JUnit Platform -- perhaps with the Vintage Engine which brings along JUnit 4.x jar.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAIK the found providers are run separately in a loop, see
AbstractSurefireMojo.java
in methodexecute
.