Run unit tests in IntelliJ IDEA from multiple modules together

Viewed 49947

How can I run all tests from two or more IDEA modules at once?

I'm using many modules and it is important to run all of the unit tests often and when I choose more than one folder to run, there's no 'run' option on the context menu any more.

7 Answers

Select all modules, right-click them and choose to run all tests. This will create a configuration called "Whole Project" which you can run again at any time.

I found this better than the accepted answer because this runs the unit tests separately for each module. If your test cases use module-specific resources during its run-time then the accepted answer's best way won't work.

Select all modules

Select all modules

Right click and choose to run all tests

Right click and choose to run all tests

Get a new run configuration

Get a new run configuration

This worked for me for a project with multiple modules.

Create a new JUnit run/debug configuration. Test kind: 'All in package' Search for tests: 'Whole project'

You will have to specify a working directory as well.

If you use Gradle and have multiple modules, you can do it that way:

  • make sure IntelliJ is set to use Gradle to run the tests (Settings/Build, Execution, Deployment/Build Tools/Gradle -> Run tests using: Gradle)
  • right click over a module in the Project navigator and select Run test in [module name]
  • once done, left click on the configuration that was created in the top toolbar and select Edit Configurations...
  • in the Run field, simply add more modules just after the first one, for example, if you want to run tests in modules foo, bar and baz: :foo:test :bar:test :baz:test --tests *
  • rename the configuration, for example Test Foo + Bar + Baz

Now you can just run the configuration to perform the tests you need.

Related