Profile JUnit in Eclipse Indigo using VisualVM

You can use JVisualVM (%JAVA_HOME%/bin/jvisualvm.exe), but to use it with JUnit, you need to change the run configuration slightly.

  1. Run the JUnit tests once, to create the run configuration
  2. Edit the Run Configuration (Run->Run Configurations...)
  3. In the Test tab check the box 'Keep JUnit running after test when debugging'
  4. Rerun the test (with Debug). This will run the tests, but importantly, leave the JVM around, so that you can attach to it using JVisualVM.

If you wish to profile a specific section of the test, then setting a breakpoint before and after will enable you to start / stop profiling.


JProfiler has an eclipse plugin which supports JUnit run configurations. See here for a screen cast on the eclipse IDE integration.

To keep the JVM alive after the test finishes (so that you can analyzed the results), edit the profiling settings and select "Keep VM alive" on the "Miscellaneous" tab.

Disclaimer: My company develops JProfiler.


A neat option to profile application startup or short running processes (like tests) with VisualVM is the Startup Profiler Plugin.

The command line argument provided by the plugin has to be copied to the launch configuration under VM arguments.