Chapter 8. JUnitPerf
Introduction
Performance issues inevitably sneak into a project. Tracking down the issues is troublesome without the proper tools. Commercial performance-monitoring tools, such as JProbe or OptimizeIt, help pinpoint performance problems. These tools excel at providing performance metrics but typically require expert human intervention to run and interpret the results. These tools are not designed to execute automatically as part of a continuous integration process—which is where JUnitPerf enters the picture.
JUnitPerf, available from
http://www.clarkware.com/software/JUnitPerf.html,
is a tool for continuous performance testing. JUnitPerf transparently
wraps, or decorates existing JUnit tests without
affecting the original test.[41] Remember that JUnit tests
should execute quickly. Figure 8-1 shows the UML
diagram for the JUnitPerf TimedTest.
Tip
JUnitPerf tests can (and should) be executed separately from normal JUnit tests. This approach ensures that the overall execution of JUnit tests isn’t hindered by the additional time spent executing JUnitPerf tests.

Figure 8-1. JUnitPerf UML diagram
Here’s a quick overview of how a JUnitPerf timed
test works. The following occurs when a JUnitPerf
TimedTest.run(TestCase) method is invoked:
Retrieve the current time (before JUnit test execution).
Call
super.run(TestResult)to run the JUnit test, wheresuperrefers to the JUnit ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access