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

 
 
 
 
Comments:

Surprise! Well, it was to me, anyway wow gold. Wowhead announced on Wednesday that they are launching a new Premium subscription service. Subscriptions cost from $2.50 to $3.33 a month, depending on how many months you subscribe for at a time, and confer the following benefits:character limit on those posts.It likely won't be easy -- of course you've got to go into Ulduar, and you've got to down Freya, and yes wow gold kaufen, a stick like this will require you to down her hard mode. That means you leave the Elders up, and oh yeah, while they're still standing, not only will they buff her damage output, but they'll give her some extra abilities to rock your world with as well. It won't be an easy fight at all. But bring her and her Elders down, and when this comes up, you can fight all of the other casters for it. Win that roll (good luck on that) or spend your DKP (more likely), and the sprig is yours.

Posted by dfvbdfb on August 21, 2009 at 03:02 AM GMT #

thanks thanks

Posted by metin2 yang on November 23, 2009 at 09:14 AM GMT #

Do you have enough [url=http://www.romolgold.com]rom gold[/url]? Is the [url=http://www.romolgold.com]runes of magic gold[/url] in the market too expensive ? Now we can offer you the cheapest.

Posted by rom on December 20, 2009 at 02:34 AM GMT #

Do you have enough rom gold? Is the runes of magic gold in the market too expensive? Now we can offer you the cheapest.

Posted by rom on December 20, 2009 at 02:34 AM GMT #

I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.so you also can read my website,if you like ugg boots

Posted by cheap ugg boots on December 25, 2009 at 02:58 AM GMT #

I recently came accross your blog and have been reading along. I thought I would leave my first comment. I dont know what to say except that I have enjoyed reading. Nice blog. I will keep visiting this blog very often.so you also can read my website,if you like ugg boots or want to buy ugg boots

Posted by ugg boots on December 25, 2009 at 02:59 AM GMT #

ugg boots ugg boots ugg boots

Posted by ugg boots on January 21, 2010 at 07:04 AM GMT #

There are many ways to get Knight Gold in the games. Now I tell some skill to get Knight online Gold in the games. Of course, you cah buy Knight online Noah in some sites. I hope you can get more Knight Noah in the game.

Posted by knight on January 22, 2010 at 07:01 AM GMT #

Post a Comment:
  • HTML Syntax: Allowed
 

« March 2010
SunMonTueWedThuFriSat
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
   
       
Today

Valid XHTML or CSS?

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