Testing in Maven
You can also pass the Maven Surefire plugin parameters when you run JUnit or TestNg tests and the Maven Failsafe plugin parameters for running integration tests. The Maven surefire plugin is declared in the super POM by default, but you can adjust its settings in your project's POM.
Open the Maven tool window.
Under the Lifecycle node select test.
Note that goals specified in the Maven surefire plugin will be activated at this phase and all tests in a project or in a module will be run.
Run a single test
If you want to run just a single test instead of all the tests declared in your project, create a Maven run configuration for a single test with the Maven
-Dtest=TestName test command. The run configuration will be saved under the Run Configurations node.
In the Maven tool window, under the Lifecycle node, right-click the test goal.
From the context menu, select Create 'name of the module/project and name of a goal'.
In the dialog that opens, specify a working directory that contains test you want to run and in the Command line field, specify a phase (specified automatically) and the
Open the Run Configurations node and double-click your configuration to run.
Maven runs the test and displays the result in the Run tool window.
You can skip running tests, for example, when you want to just compile your project and don't want to wait for Maven to complete the tests' execution.
Click the icon in the Maven tool window to open settings and select Runner from the options on the left.
On the Runner page, select Skip tests and click OK.
IntelliJ IDEA de-activates the test goal under the Lifecycle node.
The appropriate message notifying that tests are skipped is displayed in the Run tool window when you execute other goals.
Debug tests with Maven
You can debug tests executed by Maven. For example, if you want to debug tests running in a pipeline then you can fork the process and debug it remotely using Maven commands.
In your Maven project, open the Run/Debug Configurations dialog.
Add a new Remote JVM Debug configuration.
In the options on the right, add a name, change the port if needed (the default is
8000), select the module classpath and click OK.
Set the break points where needed.
Press Ctrl to open the Run Anything window. Enter the Maven command for forked tests. The default 5005 port is used for the process. However, you can change the port and run it on the local host with the following command:mvn -Dmaven.surefire.debug="-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000" test
You can check what other Maven commands can be used. For example, what to use if you don't want to fork the debugging process.
You can check the running process in the Run tool window.
Start the debugging process, by clicking against the created debug configuration on the main toolbar.
Check the result in the Debug tool window.
As the code executes, it will pause at the breakpoints you have set in your code.