Karsten Thoms

     
 

Executing JUnit tests with JMeter using Maven


Suppose you want to execute JUnit tests from JMeter to make some load or performance tests. JMeter therfore offers the JUnitSampler to execute the tests. If you then want to execute your JMeter test suite with Maven2 you will face a problem.

The blog post "Running JUnitSampler with Maven" describes already a workaround, but there is an issue if you are working on Windows.

Maven JMeter plugin

The Maven JMeter plugin is under development and the only available source is from the JMeterMavenPlugin Wiki Site. But do not download the code from there, the above mentioned blog has provides already a patched version.

Maven Dependency Plugin

The blog post shows a code snippet using the Maven Dependency Plugin. The plugin is used to dump the classpath to a file, which is read by an extended JMeter plugin to create the classpath necessary to execute the JUnit tests. The plugin is referenced with version 2.0-alpha-4.

In the meanwhile the plugin version 2.0 was released. There is a significant change from version 2.0-alpha-4. The alpha version used the colon ':' hard coded to separate path entries, but this is a serious problem for Windows systems, since you have the colon as the drive locator. This was fixed in the final version, which now uses the File.separator char. Further you could now explicitly set the separator using the pathSeparator property, which was not possible in 2.0-alpha-4.

The plugin configuration therefore must be:

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-dependency-plugin</artifactId>
  <version>2.0</version>
  <executions>
    <execution>
      <id>build-classpath</id>
      <phase>test-compile</phase>
      <goals>
        <goal>build-classpath</goal>
      </goals>
      <configuration>
        <cpFile>target/classpath</cpFile>
        <includeScope>test</includeScope>
      </configuration>
    </execution>
  </executions>
</plugin>

JUnitSampler limitations

The JUnitSampler implies that the test classes are derived from class TestCase. Therefore it does not work for:
  1. Test Suites
  2. JUnit 4 style test classes
Further the test method must not be dependend on a setup done by TestSetup class or other test wrappers, since the sampler just instantiates the test class and invokes the test method.

If setUp() and tearDown() methods should be called they must be public, otherwise they cannot be invoked.

Repository Configuration

Sometime I wonder why there are central repository sites like ibiblio if you can't find some fundamental jars there. I think I come to this back later in a separate blog post. Same problem for the JMeter jars. Of course I can download the jars and install them to my local repository, but I wanted to get the JMeter jar from a Maven repository. The only location I found was the repository at thinkpond.org

So instead of installing JMeter manually you can configure the repository:

<repositories>
  <repository>
    <id>thinkpond.org</id>
    <name>thinkpond.org Repository</name>
    <url>http://bin.thinkpond.org/repo</url>
  </repository>
</repositories>

Conclusion

It is a bit tricky to integrate JMeter in Maven. But with the tips found in the mentioned blog it is possible to manage the task. Building the JMeter plugin from source is not what I wanted to do to get things running. Also it does not seem that the mentioned workaround will go into the development of the JMeter plugin.

Executing JUnit tests using JMeter's JUnitSampler has some limitations that are annoying for JUnit 4 users. Hopefully there will come a JUnit4Sampler in future.

If you plan to use this framework stack be aware that you will have to keep a patched version of the JMeter plugin in your development environment until there will be an official solution. If you can live with the mentioned workarounds and limitations this combination can be a comfortable way to execute performance tests using Maven. Especially setting up JMeter's classpath can be tedious without Maven integration.

Appendix

Resources

Downloads

 
 
 
 
 

« February 2008 »
SunMonTueWedThuFriSat
     
1
2
3
4
5
6
7
8
9
10
11
12
13
15
16
17
18
19
20
22
23
24
27
28
 
       
Today

Valid XHTML or CSS?

[This is a Roller site]
Theme by Rowell Sotto.
 
© Karsten Thoms