Movatterモバイル変換


[0]ホーム

URL:


IntelliJ IDEA 2025.2 Help

Testing in Maven

In the Maven project, you cancreate andrun tests the same way you do in any other project using thedefault IntelliJ IDEA test runner.

Run a simple JUnit test

  1. Open your Maven project.

  2. Create or open a test class in the editor and clickthe Run button in the gutter to run it.

    Run test

    The result is displayed in theRun tool window.

    For more information about creating or running regular tests, refer to theTesting section.

You candelegate test execution to Maven.

You can also pass theMaven Surefire plugin parameters when you run JUnit or TestNg tests and theMaven 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 theMaven tool window.

  2. Under theLifecycle node, selecttest.

    the Maven tool window

    Note that goals specified in theMaven 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 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 theRun Configurations node.

  1. In theMaven tool window, under theLifecycle node, right-click thetest goal.

  2. From the context menu, selectModify Run Configuration.

  3. In the dialog that opens, specify a working directory that contains test you want to run and in theCommand line field, specify a phase (specified automatically) and the-Dtest=TestName test command.

    Run/Debug Configuration

    ClickOK.

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

    the saved Run configuration

    Maven runs the test and displays the result in theRun 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.

Theskip tests action in IntelliJ IDEA is an implementation of the-Dmaven.test.skip=true Maven command.

  1. Click thethe Maven settings icon in theMaven tool window to openMaven settings and selectRunner from the options on the left.

    In theMaven tool window, useToggle Skip Test Mode to toggle theSkip tests mode.

  2. On theRunner page, selectSkip tests and clickOK.

    the Maven settings | Runner

    IntelliJ IDEA deactivates thetest goal under theLifecycle node.

    the Maven tool window

    The appropriate message notifying that tests are skipped is displayed in theRun tool window when you execute other goals.

    the Run tool window

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.

For more information, refer to theMaven documentation and theremote debugging process.

Debug tests

  1. In your Maven project, open theRun/Debug Configurations dialog.

  2. Add a newRemote JVM Debug configuration.

  3. In the options on the right, add a name, change the port if needed (the default is8000), select the module classpath and clickOK.

    Debug configurations
  4. Set thebreak points where needed.

  5. PressCtrl twice to open theRun Anything window. Enter theMaven 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
    Local terminal

    You can check what otherMaven 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 theRun tool window.

    Run tool window
  6. Start the debugging process, by clickingthe Debug button against the created debug configuration on the main toolbar.

    Check the result in theDebug tool window.

    the Debug console tab

    As the code executes, it will pause at the breakpoints you have set in your code.

05 August 2025
Run/Debug Configuration: MavenMaven dependencies

[8]ページ先頭

©2009-2025 Movatter.jp