background image
<< Start the test | Append assertion error >>

Junit Sampler Tutorial

<< Start the test | Append assertion error >>
Junit Sampler Tutorial
This tutorial attempts to explain the basic design, functionality and usage of the new Junit
Sampler for Jmeter. The sampler was introduced in 2.1.2 release of Jmeter. Earlier releases
do not have the sampler.
Design
The current implementation supports standard Junit convention and extensions, like
oneTimeSetUp and oneTimeTearDown. Other features can be added on request. The
sampler works like the JavaSampler with some differences.
1. rather than use Jmeter's test interface, it scans the jar files for classes extending junit's
TestCase class. This means any class or subclass.
2. Junit test jar files are copied to jmeter/lib/junit instead of jmeter/lib
3. Junit sampler does not use name/value pairs for configuration. The sampler assumes
setUp and tearDown will configure the test correctly.
Note: setUp and tearDown
methods must be declared public, so that Jmeter can use it.
4. The sampler measures the elapsed time only for the test method and does not include
setUp and tearDown.
5. Each time the test method is called, Jmeter will pass the result to the listeners.
6. Support for oneTimeSetUp and oneTimeTearDown is done as a method. Since Jmeter is
multi-threaded, we cannot call oneTimeSetUp/oneTimeTearDown the same way maven
does it.
7. The sampler reports unexpected exceptions as errors.
Functionality
Here is a description of the functionalty.
Name name for the sample. This is the same as all jmeter samplers.
Package Filter provides a way to filter the classes by package name.
Classname the name of the class to test. The sampler will scan the jar files in
jmeter/lib/ext and jmeter/lib/junit for classes extending junit's TestCase.
Constructor String a string to pass to the string constructor of the test class.
Test Method the name of the method to test in the sampler.
Success message a descriptive message indicating what success means.
Success code an unique code indicating the test was successful.
Failure message a descriptive message indicating what failure means.
Failure code an unique code indicating the test failed
Error message a description for errors
Error code some code for errors. Does not need to be unique
Do not call setUp and tearDown set the sampler not to call setUp and tearDown. By
default, setUp and tearDown should be called. Not calling those methods could affect the
test and make it inaccurate. This option should be used with caution. If the selected method
is oneTimeSetUp or oneTimeTearDown, this option should be checked.