Intellij equivalent to eclipse's "keep junit running after a test run when debugging"

This is useful when it's a more heavyweight test that wires up spring contexts, creates jaxb contexts, etc. Not having to pay the jvm startup price every time can sometimes shave off between 5-10 seconds for integration tests. And if you use jrebel the test code can be changed without needing a restart.

1 comment
Comment actions Permalink

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.

1

Please sign in to leave a comment.