在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):sormuras/junit-platform-maven-plugin开源软件地址(OpenSource Url):https://github.com/sormuras/junit-platform-maven-plugin开源编程语言(OpenSource Language):Java 98.4%开源软件介绍(OpenSource Introduction):JUnit Platform Maven PluginMaven Plugin launching the JUnit Platform Features
This plugin was presented by Sander Mak at Devoxx 2018: https://youtu.be/l4Dk7EF-oYc?t=2346 PrerequisitesUsing this plugin requires at least:
Simple UsageThe following sections describe the default and minimal usage pattern of this plugin. JUnit Jupiter APIAdd test compile dependencies into your project's <dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
</dependencies> Configure the <plugin>
<groupId>de.sormuras.junit</groupId>
<artifactId>junit-platform-maven-plugin</artifactId>
<version>1.1.6</version>
<extensions>true</extensions> <!-- Necessary to execute it in 'test' phase. -->
<configuration>
<isolation>NONE</isolation> <!-- Version 1.0.0 defaults to ABSOLUTE. -->
</configuration>
</plugin> This minimal configuration uses the extensions facility to:
Pure Maven Plugin ModeIf you want to execute this plugin side-by-side with Surefire you have two options. Either use the Or omit the <plugin>
<groupId>de.sormuras.junit</groupId>
<artifactId>junit-platform-maven-plugin</artifactId>
<version>1.1.6</version>
<extensions>false</extensions> <!-- Neither install this plugin into `test` phase, nor touch Surefire. -->
<executions>
<execution>
<id>Launch JUnit Platform</id>
<phase>test</phase>
<goals>
<goal>launch</goal>
</goals>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin> Access SNAPSHOT version via JitPackCurrent <project>
<pluginRepositories>
<pluginRepository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</pluginRepository>
</pluginRepositories>
<dependency>
<groupId>com.github.sormuras</groupId>
<artifactId>junit-platform-maven-plugin</artifactId>
<version>master-SNAPSHOT</version>
</dependency>
</project> JUnit Platform ConfigurationThe following sections describe how to pass arguments to the JUnit Platform. The parameters described below are similar to those used by the Console Launcher on purpose. Class Name PatternsProvide regular expressions to include only classes whose fully qualified names match.
To avoid loading classes unnecessarily, the default pattern only includes class names that begin with The configuration below extends the default pattern to include also class names that end with <configuration>
<classNamePatterns>
<pattern>^(Test.*|.+[.$]Test.*|.*Tests?)$</pattern>
<pattern>.*TestCase</pattern>
</classNamePatterns>
</configuration> TagsTags or tag expressions to include only tests whose tags match. https://junit.org/junit5/docs/current/user-guide/#running-tests-tag-expressions <configuration>
<tags>
<tag>foo</tag>
<tag>bar</tag>
</tags>
</configuration> Additional Custom Configuration Parametershttps://junit.org/junit5/docs/current/user-guide/#running-tests-config-params <configuration>
<parameters>
<junit.jupiter.execution.parallel.enabled>true</junit.jupiter.execution.parallel.enabled>
<ninety.nine>99</ninety.nine>
</parameters>
</configuration> Selectorshttps://junit.org/junit5/docs/current/api/org/junit/platform/engine/discovery/package-summary.html <configuration>
<selectors>
<classes>
<class>JupiterTest</class>
<class>JupiterTests</class>
<class>TestJupiter</class>
</classes>
</selectors>
</configuration> All supported selectors are listed below: class Selectors {
Set<String> directories = emptySet();
Set<String> files = emptySet();
Set<String> modules = emptySet();
Set<String> packages = emptySet();
Set<String> classes = emptySet();
Set<String> methods = emptySet();
Set<String> resources = emptySet();
Set<URI> uris = emptySet();
} Plugin ConfigurationThe following sections describe how to configure the JUnit Platform Maven Plugin. Dry RunDry-run mode discovers tests but does not execute them. <configuration>
<dryRun>true|false</dryRun>
</configuration> Defaults to Global TimeoutGlobal timeout duration defaults to 300 seconds. <configuration>
<timeout>300</timeout>
</configuration> Execution ProgressDuration between output and error log file sizes during execution (JAVA execution mode only). Defaults to 60 seconds. <configuration>
<executionProgress>60</executionProgress>
</configuration> Isolation Level
<configuration>
<isolation>ABSOLUTE|ALMOST|MERGED|NONE</isolation>
</configuration> Defaults to Isolation: ABSOLUTETotal isolation.
Isolation: ALMOSTAlmost total isolation - main and test classes are put into the same layer.
Isolation: MERGEDMerge main and test layers.
Isolation: NONENo isolation, all dependencies are put into a single layer.
ExecutorThe JUnit Platform Maven Plugin supports two modes of execution: DIRECT and JAVA. <configuration>
<executor>DIRECT|JAVA</executor>
</configuration> DIRECT is the default execution mode. Executor: DIRECTLaunch the JUnit Platform Launcher "in-process". Direct execution doesn't support any special options - it inherits all Java-related settings from Maven's Plugin execution "sandbox". Executor: JAVAFork new a JVM calling class JavaOptions {
/**
* This is the path to the {@code java} executable.
*
* <p>When this parameter is not set or empty, the plugin attempts to load a {@code jdk} toolchain
* and use it to find the {@code java} executable. If no {@code jdk} toolchain is defined in the
* project, the {@code java} executable is determined by the current {@code java.home} system
* property, extended to {@code ${java.home}/bin/java[.exe]}.
*/
String executable = "";
/** Passed as {@code -Dfile.encoding=${encoding}, defaults to {@code UTF-8}. */
String encoding = "UTF-8";
/** Play nice with calling process. */
boolean inheritIO = false;
/** Override <strong>all</strong> Java command line options. */
List<String> overrideJavaOptions = emptyList();
/** Override <strong>all</strong> JUnit Platform Console Launcher options. */
List<String> overrideLauncherOptions = emptyList();
/** Additional Java command line options prepended to auto-generated options. */
List<String> additionalOptions = emptyList();
/** Argument for the {@code --add-modules} options: like {@code ALL-MODULE-PATH,ALL-DEFAULT}. */
String addModulesArgument = "";
} Example <configuration>
<executor>JAVA</executor>
<javaOptions>
<inheritIO>true</inheritIO>
<additionalOptions>
<additionalOption>--show-version</additionalOption>
<additionalOption>--show-module-resolution</additionalOption>
</additionalOptions>
</javaOptions>
</configuration> Plugin Configuration TweaksTweak options to fine-tune test execution. class Tweaks {
/** Fail test run if no tests are found. */
boolean failIfNoTests = true;
/** Enable execution of Java language's {@code assert} statements. */
boolean defaultAssertionStatus = true;
/** Use platform or thread context classloader. */
boolean platformClassLoader = true;
/** Move any test engine implementations to the launcher classloader. */
boolean moveTestEnginesToLauncherClassLoader = true;
/** Fail if worker is not loaded in isolation. */
boolean workerIsolationRequired = true;
/** A missing test output directory and no explicit selector configured: skip execution. */
boolean skipOnMissingTestOutputDirectory = true;
/** Force ansi to be disabled for java executions. */
boolean disableAnsi = false;
/** List of additional raw (local) test path elements. */
List<String> additionalTestPathElements = emptyList();
/** List of additional raw (local) launcher path elements. */
List<String> additionalLauncherPathElements = emptyList();
/** List of {@code group:artifact} dependencies to exclude from all path sets. */
List<String> dependencyExcludes = emptyList();
/** List of {@code group:artifact:version} dependencies to include in test path set. */
List<String> additionalTestDependencies = emptyList();
/** List of {@code group:artifact:version} dependencies to include in launcher path set. */
List<String> additionalLauncherDependencies = emptyList();
} Error "No tests found."If the plugin reports "No tests found." it may be due to:
Possible solutions:
<configuration>
<tweaks>
<failIfNoTests>false</failIfNoTests>
</tweaks>
</configuration> Modular Testinghttps://sormuras.github.io/blog/2018-09-11-testing-in-the-modular-world.html Modular Test ModeA test mode is defined by the relation of one main and one test module name.
Copied from junit-platform-isolator/.../TestMode.java class TestMode {
static TestMode of(String main, String test) {
var mainAbsent = main == null || main.trim().isEmpty();
var testAbsent = test == null || test.trim().isEmpty();
if (mainAbsent) {
if (testAbsent) { // trivial case: no modules declared at all
return CLASSIC;
}
return MODULAR; // only test module is present, no patching involved
}
if (testAbsent) { // only main module is present
return MODULAR_PATCHED_TEST_RUNTIME;
}
if (main.equals(test)) { // same module name
return MODULAR_PATCHED_TEST_COMPILE;
}
return MODULAR; // bi-modular testing, no patching involved
}
}
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论