Generating JUnitPerf Tests
Problem
You want to use JUnitPerfDoclet, which is an XDoclet code generator created specifically for this book, to generate and execute JUnitPerf tests.
Solution
Mark up your JUnit test methods with JUnitPerfDoclet tags and execute
the perfdoclet Ant task.
Discussion
As we were writing this book, we came up with the idea to code-generate JUnitPerf tests to show how to extend the XDoclet framework. This recipe uses that code generator, which is aptly named JUnitPerfDoclet, to create JUnitPerf tests. The concept is simple: mark up existing JUnit tests with JUnitPerfDoclet tags and execute an Ant target to generate the code.
Creating a timed test
Here is how to mark up an existing JUnit test method to create a
JUnitPerf TimedTest:
/** * @junitperf.timedtest maxElapsedTime="2000" * waitForCompletion="false" */ public void testSynchronousSearch( ) { // details left out }
The @junitperf.timedtest tag tells JUnitPerfDoclet
that it should decorate the testSynchronousSearch( ) method with a JUnitPerf TimedTest.
The maxElapsedTime attribute is mandatory and
specifies the maximum time the test method is allowed to execute (the
time is in milliseconds) or the test fails.
The waitForCompletion attribute is optional and
specifies when a failure should occur. If the value is
“true”, the total elapsed time is
checked after the test method completes. A value of
“false” causes the test to fail
immediately if the test method exceeds the maximum time allowed.
Creating a load test
Here ...
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