Reputation: 64915
I tried to do it, but it seems impossible, since you can only profile main methods. I even added a main method to using test, but it just shows the time of that main method. :(
I'm using mocks and abstract testcases, so I cannot convet it into main method.
Any ideas?
Upvotes: 3
Views: 1787
Reputation: 3472
I've found the Junit framework to be a convenient place to park ad-hoc performance tests. Sure, there are better ways to manage it, but if all you are after is fixing a hotspot and want a profile while doing so, it will suffice. My approach is:
You may want to put add a sleep up front, to allow time for you to attach. Quick and dirty.
Upvotes: 0
Reputation: 551
I would recommend using JMH + a profiler (spf4j, flight recorder)
a example on how you can do that you can see at : http://zolyfarkas.github.io/spf4j/xref-test/org/spf4j/JmhTest.html
If you use jenkins with the jmh plugin: https://github.com/blackboard/jmh-jenkins you can trend your performance, and you will always be able to look at the profiler data to investigate.
Upvotes: 0
Reputation: 18714
You could use jvisualvm from the java installation.
This tool can monitor and profile any running java application.
Upvotes: 3
Reputation: 8100
If you're trying to get performance results of the code that you're testing, that's something that's usually done by profiling the actual application as it's running in a real environment (container, executable file, etc.) Thus, I'd posit that attempting to profile the actual application code through unit tests is the incorrect way to do it, as you might not get true performance details. There are multiple reasons for this:
If instead you're actually attempting to profile your unit test cases, I'd have to ask why you'd want to do that. So long as they run "fast enough" (which is a subjective term, but "under 10 minutes" is usually a good proxy value) to get developers feedback on whether they pass or fail in a timely manner, then that should be good enough...
Upvotes: 1