### Example toolchains.xml for JDK Toolchains Source: https://maven.apache.org/surefire/maven-failsafe-plugin/java9.html Define toolchain configurations for different JDK versions, including paths, in the toolchains.xml file. ```xml jdk 1.8 sun jdk8 /path/to/openjdk8 jdk 11 sun jdk11 /path/to/openjdk/11 ``` -------------------------------- ### POJO Test Setup Method Signature Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/pojo-test.html Implement this method to set up resources before each POJO test method is executed. ```java public void setUp(); ``` -------------------------------- ### Include Patterns File Example Source: https://maven.apache.org/surefire/maven-failsafe-plugin/xref/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Specifies include patterns for integration tests. Supports file paths, simple patterns, regex, and method filtering. ```java *{@literal /}it{@literal /}* **{@literal /}NotIncludedByDefault.java %regex[.*IT.*|.*Not.*] ``` ```java pkg.SomeIT#testMethod ``` -------------------------------- ### Trace Forked Execution Output Source: https://maven.apache.org/surefire/maven-failsafe-plugin/developing.html Install the Surefire plugin and filter the output to trace the communication of the forked Surefire process. ```bash mvn -e -X install | grep Forking ``` -------------------------------- ### Basic Java Classpath Execution Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/class-loading.html This is a basic command-line example of how to launch a Java application with a specified classpath. It may encounter issues on operating systems with command-line length limitations. ```bash 1. java -classpath foo.jar:bar.jar MyApp ``` -------------------------------- ### Running Individual Integration Tests Source: https://maven.apache.org/surefire/maven-failsafe-plugin/xref/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html This example demonstrates how to use the `it.test` parameter to run specific integration tests. It supports complex patterns including method execution and exclusion patterns. ```properties -Dit.test=MyIT -Dit.test=MyIT#myMethod -Dit.test=???IT, !Unstable*, pkg/\*/Ci*leIT.java, *IT#test*One+testTwo?????, #fast*+slowTest ``` -------------------------------- ### Example 1-Line Error Summary Output Source: https://maven.apache.org/surefire/maven-failsafe-plugin/newerrorsummary.html This output demonstrates the compact one-line format for test failures and errors, highlighting assertion failures and exceptions with trimmed messages and library call indicators. ```text Failures: Test1.assertion1:59 Bending maths expected:<[123]> but was:<[312]> Test1.assertion2:64 True is false Errors: Test1.nullPointerInLibrary:38 » NullPointer Test1.failInMethod:43->innerFailure:68 NullPointer Fail here Test1.failInLibInMethod:48 » NullPointer Test1.failInNestedLibInMethod:54->nestedLibFailure:72 » NullPointer Test2.test6281:33 Runtime FailHere ``` -------------------------------- ### Configure Jetty Plugin to Stop Previous Instances Source: https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html This configuration snippet shows how to bind the 'stop' goal to the 'pre-integration-test' phase before the 'start' goal. This is useful for ensuring any previously running Jetty instance is stopped before starting a new one for integration tests. ```xml [...] [...] [...] org.eclipse.jetty jetty-maven-plugin 9.2.2.v20140723 [...] [...] start-jetty pre-integration-test stop start [...] [...] [...] [...] [...] [...] ``` -------------------------------- ### Complex Include Syntax Example Source: https://maven.apache.org/surefire/maven-failsafe-plugin/xref/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Demonstrates the advanced syntax for specifying test includes, supporting regex and exclusion patterns. This is useful for fine-grained test selection. ```xml %regex[.*[Cat|Dog].*], Basic????, !Unstable* ``` ```xml %regex[.*[Cat|Dog].*], !%regex[pkg.*Slow.*.class], pkg/**/ *Fast*.java ``` -------------------------------- ### Configure Failsafe and Jetty Plugins for Integration Tests Source: https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html This configuration binds Jetty's start and stop goals to pre-integration-test and post-integration-test phases, respectively. It also configures the Failsafe plugin for integration-test and verify goals. Ensure the Jetty plugin is configured with a stop port and key. ```xml [...] [...] [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 integration-test integration-test verify verify org.eclipse.jetty jetty-maven-plugin 9.2.2.v20140723 [...] [...] 10 8005 STOP [...] [...] [...] start-jetty pre-integration-test start 0 true stop-jetty post-integration-test stop [...] [...] [...] [...] [...] ``` -------------------------------- ### Manifest-Only JAR Classpath Execution Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/class-loading.html This example demonstrates launching an application using a manifest-only JAR. This approach uses the JAR's manifest file to specify additional JARs for the classpath, potentially avoiding command-line length issues. ```bash 1. java -classpath booter.jar MyApp ``` -------------------------------- ### Exclude Patterns File Example Source: https://maven.apache.org/surefire/maven-failsafe-plugin/xref/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Specifies exclude patterns for integration tests. Supports file paths, simple patterns, regex, and method filtering. ```java *{@literal /}it{@literal /}* **{@literal /}DontRunIT.* %regex[.*IT.*|.*Not.*] ``` ```java pkg.SomeIT#testMethod ``` -------------------------------- ### getBasedir Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the base directory for the project. ```APIDOC ## Method getBasedir ### Description Gets the base directory for the project. ### Method `public File getBasedir()` ``` -------------------------------- ### Clone Maven Failsafe Plugin Repository (Anonymous Access) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/scm.html Use this command to check out the source code anonymously. Ensure Git is installed and configured. ```bash git clone --branch surefire-3.5.6 https://github.com/apache/maven-surefire.git ``` -------------------------------- ### Run Docker Container (Windows/macOS) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/docker.html Runs the built Docker image interactively, allocating a pseudo-TTY. The container is removed automatically upon exit (`--rm`). It starts a shell session inside the container. ```bash $ docker run -it --rm my-image:1 /bin/sh ``` -------------------------------- ### Configure Failsafe Plugin for Jupiter and Vintage Engine Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/junit-platform.html This setup enables running tests with both the JUnit 5 Jupiter engine and the JUnit Vintage engine by including their dependencies. ```xml org.junit.jupiter junit-jupiter-engine 5.9.1 test org.junit.vintage junit-vintage-engine 5.9.1 test ``` -------------------------------- ### getMainBuildPath Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the main build path, which can be an output directory or an artifact file. ```APIDOC ## Method getMainBuildPath ### Description Gets the main build path, which can be an output directory or an artifact file. If not forking the JVM, parameter `useSystemClassLoader` is ignored and the `IsolatedClassLoader` is used instead. See the resolution of `ClassLoaderConfiguration`. ### Method `public File getMainBuildPath()` ``` -------------------------------- ### Set JAVA_HOME for Java 9 Source: https://maven.apache.org/surefire/maven-failsafe-plugin/java9.html Set the JAVA_HOME environment variable to point to your Java 9 installation before running Maven tests. ```bash $ export JAVA_HOME=/path/to/jdk9 $ mvn test ``` -------------------------------- ### Child Project Usage in Multi-Module Setup Source: https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html Child projects can trigger the Failsafe Plugin configuration defined in the parent POM. This snippet shows a minimal configuration in a child project's POM. ```xml [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 [...] ``` -------------------------------- ### Complex Exclude Syntax Example Source: https://maven.apache.org/surefire/maven-failsafe-plugin/xref/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Demonstrates the advanced syntax for specifying test excludes, including regex patterns. This allows for precise exclusion of specific test classes or patterns. ```xml %regex[pkg.*Slow.*.class], Unstable* ``` -------------------------------- ### Run Docker Container (Linux) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/docker.html Runs the built Docker image interactively on Linux systems, allocating a pseudo-TTY. Requires `sudo`. The container is removed automatically upon exit (`--rm`). It starts a shell session inside the container. ```bash $ sudo docker run -it --rm my-image:1 /bin/sh ``` -------------------------------- ### Parent POM Configuration for Multi-Module Projects Source: https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html Define a shared Failsafe Plugin configuration in a parent POM with an execution ID. This allows child projects to easily override or extend the configuration. This example groups 'integration-test' and 'verify' goals under a single execution. ```xml [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 integration-test integration-test verify [...] ``` -------------------------------- ### Run Sample Integration Test Source: https://maven.apache.org/surefire/maven-failsafe-plugin/developing.html Navigate to a specific integration test resource directory and verify the build with a specified Surefire version. ```bash cd surefire-its/src/test/resources/failsafe-buildfail mvn -Dsurefire.version=2.12 verify ``` -------------------------------- ### getEncoding Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the encoding for file operations. ```APIDOC ## Method getEncoding ### Description Gets the encoding for file operations. ### Method `public String getEncoding()` ``` -------------------------------- ### getReportFormat Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the format for test reports. ```APIDOC ## Method getReportFormat ### Description Gets the format for test reports. ### Method `public String getReportFormat()` ``` -------------------------------- ### getTest Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the specific test to be executed. ```APIDOC ## Method getTest ### Description Gets the specific test to be executed. ### Method `public String getTest()` ``` -------------------------------- ### getReportsDirectory Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the directory where reports are generated. ```APIDOC ## Method getReportsDirectory ### Description Gets the directory where reports are generated. ### Method `public File getReportsDirectory()` ``` -------------------------------- ### getForkedProcessTimeoutInSeconds Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the timeout in seconds for a forked process. ```APIDOC ## Method getForkedProcessTimeoutInSeconds ### Description Gets the timeout in seconds for a forked process. ### Method `public int getForkedProcessTimeoutInSeconds()` ``` -------------------------------- ### getDebugForkedProcess Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the debug options for a forked process. ```APIDOC ## Method getDebugForkedProcess ### Description Gets the debug options for a forked process. ### Method `public String getDebugForkedProcess()` ``` -------------------------------- ### Clone Surefire Repository Source: https://maven.apache.org/surefire/maven-failsafe-plugin/developing.html Check out the complete Surefire module from the official Git repository to begin development. ```bash git clone https://gitbox.apache.org/repos/asf/maven-surefire.git ``` -------------------------------- ### getParallelTestsTimeoutInSeconds Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the timeout in seconds for parallel test execution. ```APIDOC ## Method getParallelTestsTimeoutInSeconds ### Description Gets the timeout in seconds for parallel test execution. ### Method `public double getParallelTestsTimeoutInSeconds()` ``` -------------------------------- ### getForkedProcessExitTimeoutInSeconds Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the exit timeout in seconds for a forked process. ```APIDOC ## Method getForkedProcessExitTimeoutInSeconds ### Description Gets the exit timeout in seconds for a forked process. ### Method `public int getForkedProcessExitTimeoutInSeconds()` ``` -------------------------------- ### getTestClassesDirectory Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the directory containing test class files. ```APIDOC ## Method getTestClassesDirectory ### Description Gets the directory containing test class files. ### Method `public File getTestClassesDirectory()` ``` -------------------------------- ### Build Docker Image (Windows/macOS) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/docker.html Builds a Docker image from the current directory using a Dockerfile. The `--no-cache` flag ensures that the image is built without using cached layers. The image is tagged as `my-image:1`. ```bash $ docker build --no-cache -t my-image:1 -f ./Dockerfile . ``` -------------------------------- ### getParallelTestsTimeoutForcedInSeconds Source: https://maven.apache.org/surefire/maven-failsafe-plugin/apidocs/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html Gets the forced timeout in seconds for parallel test execution. ```APIDOC ## Method getParallelTestsTimeoutForcedInSeconds ### Description Gets the forced timeout in seconds for parallel test execution. ### Method `public double getParallelTestsTimeoutForcedInSeconds()` ``` -------------------------------- ### Configure Security Policy File for All Providers Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/junit.html Define a security policy file and configure it using the 'argLine' parameter to allow all providers to run with Surefire. This approach affects test policies. ```xml [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 -Djava.security.manager -Djava.security.policy=${basedir}/src/test/resources/java.policy [...] ``` -------------------------------- ### Original Multi-line Exception Message Source: https://maven.apache.org/surefire/maven-failsafe-plugin/multilineexceptions.html An example of a multi-line exception message before Surefire's special handling. ```java java.lang.IllegalArgumentException: My Couch | May not contain whitespace ``` -------------------------------- ### VerifyMojo Constructor with Logger Source: https://maven.apache.org/surefire/maven-failsafe-plugin/xref/org/apache/maven/plugin/failsafe/VerifyMojo.html Initializes the VerifyMojo with a provided Logger instance. This is useful for testing or custom logging configurations. ```java public VerifyMojo(Logger logger) { this.logger = logger; } ``` -------------------------------- ### Define JDK 9 Toolchain in toolchains.xml Source: https://maven.apache.org/surefire/maven-failsafe-plugin/java9.html Configure a specific JDK 9 toolchain, including its version and home directory, in the toolchains.xml file. ```xml jdk 9 oracle jdk9 /path/to/jdk9 ``` -------------------------------- ### Get Directory Scanner (Pre-2.12.2) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/api.html Before version 2.12.2, providers used getDirectoryScanner() to obtain the scanner. This method is deprecated. ```java 1. directoryScanner = booterParameters.getDirectoryScanner(); 2. final TestsToRun scanResult = directoryScanner.locateTestClasses( testClassLoader, testChecker ); ``` -------------------------------- ### Skip All Tests via Command Line Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/skipping-tests.html Execute tests using the command line with '-DskipTests=true' to skip all tests, including those run by the Surefire and Failsafe plugins. ```bash mvn install -DskipTests ``` -------------------------------- ### Run Multiple Test Classes by Name and Pattern Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/single-test.html Combine specific test class names and patterns, separated by commas, to execute a selected set of tests. ```bash mvn -Dit.test=ITSquare,ITCi*le verify ``` -------------------------------- ### Separate Executions for Integration Test and Verify Goals Source: https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html For complex builds, it is recommended to separate the 'integration-test' and 'verify' goals into distinct executions. This provides more granular control over the build process. ```xml [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 integration-test integration-test verify verify [...] ``` -------------------------------- ### Run Integration Tests Multiple Times Source: https://maven.apache.org/surefire/maven-failsafe-plugin/usage.html Configure multiple executions of the 'integration-test' goal with unique summary files. The 'verify' goal aggregates these summaries to fail the build if any execution fails. This is useful for running tests with different configurations. ```xml [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 integration-test-red-bevels integration-test red target/failsafe-reports/failsafe-summary-red-bevels.xml integration-test-no-bevels integration-test none target/failsafe-reports/failsafe-summary-no-bevels.xml verify verify target/failsafe-reports/failsafe-summary-red-bevels.xml target/failsafe-reports/failsafe-summary-no-bevels.xml [...] ``` -------------------------------- ### Configuring JVM via Maven Toolchains (Version) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html Allows configuration of the test JVM using Maven toolchains, specifying only the required JDK version. This avoids hardcoding paths and is mutually exclusive with the 'jvm' parameter. ```xml ... 1.11 ``` -------------------------------- ### Get Scan Result (2.12.2+) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/api.html From version 2.12.2 onwards, providers should use getScanResult() to obtain scan results and then apply filters. The getDirectoryScanner() method is deprecated. ```java 1. scanResult = booterParameters.getScanResult(); 2. final TestsToRun testsToRun = scanResult.applyFilter(testChecker, testClassLoader ); ``` -------------------------------- ### Run a Single Test Class Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/single-test.html Execute a specific integration test class by setting the `it.test` property to the test class name. ```bash mvn -Dit.test=ITCircle verify ``` -------------------------------- ### Run Maven Tests with Toolchains XML Source: https://maven.apache.org/surefire/maven-failsafe-plugin/java9.html Execute Maven tests using a specified toolchains.xml file to select the appropriate JDK. ```bash $ mvn -t /path/to/.m2/toolchains.xml test ``` -------------------------------- ### Debug Forked Tests with Custom Port Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/debugging.html Configure a different port for remote debugging by specifying the address in the `maven.failsafe.debug` property. This example uses port 8000. ```bash mvn -Dmaven.failsafe.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000" verify ``` -------------------------------- ### Locate and Order Test Classes (2.11+) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/api.html Starting with version 2.11, providers must implement an additional step to order the located test classes using the RunOrderCalculator. ```java 1. TestsToRun scanned = directoryScanner.locateTestClasses( testClassLoader, scannerFilter ); 2. return providerParameters.getRunOrderCalculator().orderTestClasses( scanned ); ``` -------------------------------- ### Detailed Console Logs with Maven CLI Options Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/logging.html Enables detailed logging for Surefire and Failsafe plugins by appending Maven CLI options such as -X, --debug, or -e to the Maven command. This reveals suppressed information like report directories and provider configurations. ```text 1. [INFO] Surefire report directory: /path/to/project/target/surefire-reports 2. [INFO] Using configured provider org.apache.maven.surefire.junitcore.JUnitCoreProvider 3. [INFO] parallel='none', perCoreThreadCount=true, threadCount=0, useUnlimitedThreads=false, threadCountSuites=0, threadCountClasses=0, threadCountMethods=0, parallelOptimized=true 4. Configuring TestNG with: TestNGMapConfigurator ``` -------------------------------- ### Run Tests Using Patterns Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/single-test.html Use wildcard patterns with the `it.test` property to run multiple test classes that match the pattern. ```bash mvn -Dit.test=ITCi*le verify ``` -------------------------------- ### Configure Failsafe Plugin to Use Project Classes Source: https://maven.apache.org/surefire/maven-failsafe-plugin/faq.html Configure the 'classesDirectory' parameter to use main project classes in the test classpath instead of the default project artifact file. ```xml ${project.build.outputDirectory} ``` -------------------------------- ### Dockerfile for Maven Project Source: https://maven.apache.org/surefire/maven-failsafe-plugin/docker.html A simple Dockerfile that uses a Maven base image and copies the project files from the current directory into the image. ```dockerfile FROM maven:3.5.3-jdk-8-alpine COPY ./. / ``` -------------------------------- ### UnsupportedClassVersionError Example Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/toolchains.html This exception indicates that the Surefire plugin is attempting to run with a Java version that is too old for the current Surefire version. Ensure your toolchain meets the minimum Java version requirements. ```java Exception in thread "main" java.lang.UnsupportedClassVersionError: org/apache/maven/surefire/booter/ForkedBooter: Unsupported major.minor version 52.0 at java.lang.ClassLoader.defineClass1(Native Method) at java.lang.ClassLoader.defineClass(ClassLoader.java:800) at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142) at java.net.URLClassLoader.defineClass(URLClassLoader.java:449) at java.net.URLClassLoader.access$100(URLClassLoader.java:71) at java.net.URLClassLoader$1.run(URLClassLoader.java:361) at java.net.URLClassLoader$1.run(URLClassLoader.java:355) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:354) at java.lang.ClassLoader.loadClass(ClassLoader.java:425) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308) at java.lang.ClassLoader.loadClass(ClassLoader.java:358) at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482) ``` -------------------------------- ### Complex Include Patterns with Regex and Wildcards Source: https://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html Demonstrates advanced include patterns using regex and wildcards for flexible test selection. Supports comma-separated entries for multiple patterns. ```xml %regex[.*[Cat|Dog].*], Basic????, !Unstable* %regex[.*[Cat|Dog].*], !%regex[pkg.*Slow.*.class], pkg/**/*Fast*.java ``` -------------------------------- ### Configure Alternate Toolchain for Failsafe Tests Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/toolchains.html Use the `jdkToolchain` configuration within the Failsafe plugin to specify an alternate toolchain for running tests. This requires a corresponding entry in your `toolchains.xml`. ```xml [...] 8 zulu [...] ``` -------------------------------- ### Configure TestNG Suite XML Files Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/testng.html Configure the Maven Failsafe Plugin to use TestNG suite XML files for flexible test execution. ```xml [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 testng.xml [...] ``` -------------------------------- ### Configure JUnit 5 Reports with @DisplayName Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/junit-platform.html Configure specific reporters for JUnit 5 to enable phrased names with @DisplayName. This example shows configuration for stateless testset reporters and console output reporters. ```xml org.apache.maven.plugins maven-failsafe-plugin 3.5.6 false 3.0.2 false true true true false UTF-8 false false false true true ``` -------------------------------- ### Filter Tests by Name using TestNG Suite XML Source: https://maven.apache.org/surefire/maven-failsafe-plugin/examples/testng.html Run specific tests defined in a TestNG suite XML file by matching names in the 'testnames' property. This example runs 'a-t1' and 'a-t3'. ```xml [...] org.apache.maven.plugins maven-failsafe-plugin 3.5.6 [...] src/test/resources/suite.xml testnames a-t1,a-t3 [...] [...] ``` ```xml ``` -------------------------------- ### IntegrationTestMojo Configuration Parameters Source: https://maven.apache.org/surefire/maven-failsafe-plugin/xref/org/apache/maven/plugin/failsafe/IntegrationTestMojo.html This section outlines the various parameters that can be configured for the IntegrationTestMojo, which is responsible for running integration tests. ```APIDOC ## IntegrationTestMojo Configuration Parameters ### Description Provides configuration options for the IntegrationTestMojo, allowing fine-grained control over integration test execution. ### Parameters #### Debugging and Forking * **debugForkedProcess** (String) - Optional - Specifies a debug port for the forked process. * **forkedProcessTimeoutInSeconds** (int) - Optional - Sets the timeout in seconds for the forked process. * **forkedProcessExitTimeoutInSeconds** (int) - Optional - Sets the timeout in seconds for the forked process to exit. #### Parallel Test Execution * **parallelTestsTimeoutInSeconds** (double) - Optional - Sets the timeout in seconds for parallel test execution. * **parallelTestsTimeoutForcedInSeconds** (double) - Optional - Sets the forced timeout in seconds for parallel test execution. #### Class Loading and Manifest * **useSystemClassLoader** (boolean) - Optional - Specifies whether to use the system classloader. * **useManifestOnlyJar** (boolean) - Optional - Specifies whether to use a manifest-only JAR. #### Encoding and Test Failure Handling * **encoding** (String) - Optional - Sets the encoding for test output. * **testFailureIgnore** (boolean) - Optional - If set to true, test failures are ignored (deprecated behavior). * **failIfNoSpecifiedTests** (boolean) - Optional - Determines if the build should fail if no tests are specified. A warning is issued if the deprecated property is used. * **skipAfterFailureCount** (int) - Optional - The number of test failures after which to skip subsequent tests. #### Includes and Excludes * **includes** (List) - Optional - A list of include patterns for tests. * **excludes** (List) - Optional - A list of exclude patterns for tests. #### File Configuration * **systemPropertiesFile** (File) - Optional - Specifies a file containing system properties. * **summaryFile** (File) - Optional - Specifies a file for the test summary. #### Plugin Specific * **skipITs** (boolean) - Optional - Flag to skip integration tests. * **shutdown** (String) - Optional - Specifies the shutdown mode for the plugin. ### Note Some parameters like `testFailureIgnore` and `failIfNoSpecifiedTests` have deprecated aspects or behaviors that are noted in their descriptions. ``` -------------------------------- ### Configuring JVM via Maven Toolchains (Version and Vendor) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/integration-test-mojo.html Configures the test JVM using Maven toolchains, specifying both the required JDK version and vendor. This provides more precise control over the JVM selection. ```xml ... 1.8 zulu ``` -------------------------------- ### Build Docker Image (Linux) Source: https://maven.apache.org/surefire/maven-failsafe-plugin/docker.html Builds a Docker image from the current directory using a Dockerfile on Linux systems. Requires `sudo`. The `--no-cache` flag ensures that the image is built without using cached layers. The image is tagged as `my-image:1`. ```bash $ sudo docker build --no-cache -t my-image:1 -f ./Dockerfile . ```