My Opera is closing 3rd of March

mateamargo

el mate dulce no es mate

Running JUnitSampler with Maven

, , ,

If you are using Maven and want to automacally run JMeter tests, you can follow the instructions given at JMeterMavenPlugin Blog, or the more detailed Robbrecht van Amerongen post at AMIS Technology blog.

The problem is when you want to use the JUnitSampler to measure your JUnit tests, because in the time of running, the classpath of the required classes and jars are not setted and you'll get Couldn't create an instance of the class in the resulting XML report.

I'll describe the workaround to get this running.

  • I have added the maven-dependency-plugin to the project to dump a text file with the required jars (including the transitives)
  • I have modified the maven-jmeter-plugin to read this file and add those files to the classpath, using the ClassPathHacker class found at the Java Forum with a little modification.


The only problem is that the maven-dependency-plugin is still in development, and currently doesn't support including dependencies with the test scope, so you have to change the scope of your dependencies until this issue has been solved.

You have to modify your pom.xml with the following lines:

<build>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-dependency-plugin</artifactId>
            <version>2.0-alpha-4</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>
        <plugin>
            <groupId>org.apache.jmeter</groupId>
            <artifactId>maven-jmeter-plugin</artifactId>
            <version>1.0-SNAPSHOT</version>
            <executions>
                <execution>
                    <phase>test-compile</phase>
                    <id>jmeter-tests</id>
                    <configuration>
                        <reportDir>target/jmeter</reportDir>
                        <classpathDump>target/classpath</classpathDump>
                    </configuration>
                    <goals>
                        <goal>jmeter</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
    </plugins>
</build>


After doing this, the JMeter with the JUnitSampler tests will be run with mvn test-compile.

Downloads

maven-jmeter-plugin.zip

The first postA Servlet to crop an image

Comments

boktor Tuesday, October 2, 2007 11:40:25 AM

Hi Lean, nice of you to sort this out.
Perhaps you also should post this to the maven users list (http://mail-archives.apache.org/mod_mbox/maven-users/) there are several questions about setting the classpath.

Robbrecht

Write a comment

New comments have been disabled for this post.