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.

JUnitPerf UML diagram

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:

  1. Retrieve the current time (before JUnit test execution).

  2. Call super.run(TestResult) to run the JUnit test, where super refers to the JUnit ...

Get Java Extreme Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.