Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IntelliJ: Keep junit running during Integration Testing

With Eclipse and Spring Tool Suite when creating a Debug configuration we can check the Keep JUnit running after a test run when debugging. Because we're using the SpringJUnit4ClassRunner and loading the Spring app before running, startup time before these test can run is significant so this is a huge time saver for rerunning tests and even hotswapping basic changes.

However, I recently switched to IntelliJ and I'm unable to find an equivalent option for this feature. Can someone tell me where it is?

like image 322
IcedDante Avatar asked Sep 08 '25 01:09

IcedDante


1 Answers

You can achieve something very similar to Eclipse's "Keep JUnit running after a test run when debugging" by doing the following:

  1. Create a new JUnit Run/Debug configuration with Test kind set to Method and Repeat to Until Stopped
  2. Choose your test class and the method you plan to test and save the configuration
  3. Now, start the test in Debug mode using the configuration you just created. You will notice that the test will run over and over again without reloading the Spring context.
  4. Hit the sort a-z button in the Debug tab so that the latest JUnit test run is always shown at the top
  5. Pause the test from the Debug or Run tab (the || button on the left)
  6. Make your changes to the code and then build. Changes will be hot swapped. For the best results, I recommend also using HotSwap Agent or JRebel
  7. Resume the test from the Debug or Run tab
  8. Rinse and repeat from 5 to 7 until you are done with the test

Note that pausing the test is optional, changes will be reloaded anyway between test runs.

The only downside of this strategy is that you can only keep-alive test one method at a time.

like image 100
Andrei Pietrusel Avatar answered Sep 09 '25 21:09

Andrei Pietrusel