How can I profile a JUnit Test, preferentially with Eclipse integrated support? I'm trying to do it using VisualVM but apparently it can't be done.
I'm using Windows 7 x64, Eclipse Indigo, jdk 1.6, jre-j9 and JUnit 3 (I could use v.4)
Java VisualVM enables you to take profiler snapshots to capture the results of a profiling session. A profiler snapshot captures the results at the moment the snapshot is taken. To take a snapshot, click the Take Snapshot of Collected Results button in the toolbar while a profiling session is in progress.
IntelliJ IDEA To set up VisualVM in Idea, first download the VisualVM Launcher jar. Open up the plugins settings page and install it by selecting 'Install plugin from disk'. Relaunch Idea and go to the new VisualVM Launcher settings page. Set the path to your jvisualvm.
You can use JVisualVM (%JAVA_HOME%/bin/jvisualvm.exe
), but to use it with JUnit, you need to change the run configuration slightly.
Run->Run Configurations...
)Test
tab check the box 'Keep JUnit running after test when debugging'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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With