Tuesday, May 04, 2010

Running a Maven junit test in JMeter for performance testing

We needed to load test a remote service. I already had a JUnit test written to test the service so the logical thing was to see if we could get JMeter to use it.

This pdf describes how to set it up, the problem being getting the right jars from Maven.

First you need to get Maven to produce a jar file of all your unit tests -

 
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>test-jar</id>
<phase>package</phase>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>


This will create a jar in your target directory with the JUnit tests in your project.

Next you need to export the dependency jars. Add this to your pom.xml -

 
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>assembly.xml</descriptor>
</descriptors>
</configuration>
</plugin>



and create an assembly.xml file that looks a bit like this -

 
<?xml version="1.0" encoding="UTF-8"?>
<assembly>
<id>dependencies</id>
<includeBaseDirectory>false</includeBaseDirectory>
<dependencySets>
<dependencySet>
<outputDirectory></outputDirectory>
<unpack>false</unpack>
<scope>test</scope>
</dependencySet>
</dependencySets>
</assembly>


Note how the scope is set to test - this makes sure all the dependencies scoped as test in your pom are included as well.

Now run the assembly:directory goal from the command line to generate all the dependent jars.

Now all you have to do is copy all these jars into your jmeter/lib/junit directory as the pdf describes and you're away.... just make sure you follow it to the letter.

2 comments:

Sampath's Blog said...

I have tried, biut there's no outcome, Is this steps worked for you? can you give us bit more details?

Anonymous said...

It worked for me .. although i have copied the dependency jars in folder lib and the junit testcase jar in lib/junit folder.. and then it worked like a charm..
thanks for the post..