IntelliJ IDEA 2019.2 Help

Work with tests in Maven

In the Maven project, you can create and run tests the same way you do in any other project using the default IntelliJ IDEA test runner.

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.

Run tests

  1. Open the Maven tool window.

  2. 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, —Āreate 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.

  1. In the Maven tool window, under the Lifecycle node, right-click the test goal.

  2. From the context menu, select Create 'name of the module/project and name of a goal'.

  3. 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 -Dtest=TestName test command. Click OK.

    Run/Debug Configuration

  4. Open the Run Configurations node and double-click your configuration to run.

    the saved Run configuration
    Maven runs the test and displays the result in the Run tool window.

Skip tests

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.

  1. Click the icons general settings svg icon in the Maven tool window to open Maven settings and select Runner from the options on the left.
  2. On the Runner page, select Skip tests and click OK.

    the Maven settings | Runner
    IntelliJ IDEA de-activates the test goal under the Lifecycle node.
    the Maven tool window
    The appropriate message notifying that tests are skipped is displayed in the Run tool window when you execute other goals.
    the Run tool window

Last modified: 17 October 2019