Running JUnitSampler with Maven
Thursday, September 27, 2007 4:55:56 PM
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.