Sunday, 15 April 2012

junit4 - Running EMMA with JMockit and JUnit in Maven -



junit4 - Running EMMA with JMockit and JUnit in Maven -

i have problem when running emma code coverage tool jmockit + junit in maven.

i have project , using jmockit mocking framework in it.

once run mvn test running without problem. that’s means jmockit initializing junit in proper way.

following way how define dependency jmockit , junit within pom (in exact order).

<dependency> <groupid>com.googlecode.jmockit</groupid> <artifactid>jmockit</artifactid> <version>1.7</version> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <version>4.11</version> <scope>test</scope> </dependency>

but when check project code coverage emma, says

java.lang.illegalstateexception: jmockit wasn't initialized; check jmockit.jar precedes junit.jar in classpath (if using junit; if not, check documentation)

but think have configured emma plugin correctly , given below,

<build> <defaultgoal>install</defaultgoal> <plugins> <!—some other plugins here --> <plugin> <groupid>org.codehaus.mojo</groupid> <artifactid>emma-maven-plugin</artifactid> <version>1.0-alpha-3</version> <inherited>true</inherited> <configuration> <check> <classrate>100</classrate> <methodrate>100</methodrate> <blockrate>70</blockrate> <haltonfailure>false</haltonfailure> </check> </configuration> <executions> <execution> <goals> <goal>check</goal> </goals> </execution> </executions> <dependencies> <dependency> <groupid>com.googlecode.jmockit</groupid> <artifactid>jmockit</artifactid> <version>1.7</version> </dependency> <dependency> <groupid>junit</groupid> <artifactid>junit</artifactid> <scope>runtime</scope> <version>${junit.version}</version> </dependency> </dependencies> </plugin> </plugins>

can grab wrong there ?

i able figured out went wrong there. seems need junit utilize jmockit when work emma.

we can using maven-surefire-plugin.

we need add together next configuration pom.

<plugin> <groupid>org.apache.maven.plugins</groupid> <artifactid>maven-surefire-plugin</artifactid> <version>2.17</version> <configuration> <argline>-javaagent:${settings.localrepository}/com/googlecode/jmockit/jmockit/1.7/jmockit-1.7.jar</argline> <usesystemclassloader>true</usesystemclassloader> </configuration> </plugin>

note: create sure alter location of jmockit jar in above configuration.

further, not need have dependencies within emma plugin configuration. having them in dependencies section in pom (in exact order) enough.

references: jmockit - initialization problem

maven-2 junit4 jmockit

No comments:

Post a Comment