8.1 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. Remember that JUnit tests
should execute quickly. Figure 8-1 shows the UML
diagram for the JUnitPerf TimedTest.
|
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.
|
|
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,
where super refers to the JUnit
TestDecorator.
Retrieve the current time (after JUnit test execution).
If the elapsed time turns out to be greater than the maximum allowed
time, then a
junit.framework.AssertionFailedError(String) is
thrown. Otherwise, the test passes.
|