[
http://jira.codehaus.org/browse/SUREFIRE-298?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_106306
]
Julian Wood commented on SUREFIRE-298:
--------------------------------------
Here's a cut down pom. Use the apache profile as described here:
http://maven.apache.org/guides/development/guide-plugin-snapshot-repositories.html
You need to install mockit into your local repository yourself:
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
<?xml version="1.0" encoding="utf-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ca.ucalgary.it</groupId>
<artifactId>gdir</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-clean-plugin</artifactId>
<version>2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-release-plugin</artifactId>
<version>2.0-beta-4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>2.0-beta-5</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.4-SNAPSHOT</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven</groupId>
<artifactId>maven-archiver</artifactId>
<version>2.0.1</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-javaagent:${user.home}/.m2/repository/mockit/jmockit/0.8.5/jmockit-0.8.5.jar</argLine>
<useSystemClassLoader>true</useSystemClassLoader>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>mockit</groupId>
<artifactId>jmockit</artifactId>
<version>0.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mockit</groupId>
<artifactId>jmockit-asm2</artifactId>
<version>0.8.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.8</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
> Problem using -javaagent
> ------------------------
>
> Key: SUREFIRE-298
> URL: http://jira.codehaus.org/browse/SUREFIRE-298
> Project: Maven Surefire
> Issue Type: Bug
> Components: classloading
> Affects Versions: 2.0 (2.2 plugin)
> Environment: Windows XP
> Reporter: Bård Dybwad Kristensen
> Fix For: 2.4
>
>
> I try to run the JMockit framework in my tests to do some mocking of static
> classes.
> I supply the argLine arguments as follows (some spaces added to avoid
> smileys):
> <configuration>
> <argLine>-javaagent:D : \
> .m2\repository\jmockit\jmockit\0.83\jmockit-0.83.jar</argLine>
> <forkMode>once</forkMode>
> </configuration>
> This does not work. The problem is that the Mockit class is not able to find
> neither the class it is suppose to mock nor the class to use as a mock. I
> have made two small classes, Math and MockMath each with one similar method
> and one static String constant. My setup-method in the testclass is as
> follows:
> protected void setUp() throws Exception {
> super.setUp();
> System.out.println(Math.TEST);
> System.out.println(MockMath.TEST);
> Mockit.redefineMethods(Math.class, MockMath.class);
> }
> When I run this, the two System.out.printlns runs Ok, and prints what it
> should, but the Mockit class returns the following error:
> java.lang.RuntimeException: Failed to read class file for
> no.ergo.ec.vaktplan.MockMath
> at mockit.Mockit.readClassFile(Mockit.java:228)
> at mockit.Mockit.collectMockMethods(Mockit.java:191)
> at mockit.Mockit.redefineMethods(Mockit.java:176)
> at mockit.Mockit.redefineMethods(Mockit.java:162)
> at no.ergo.ec.vaktplan.TestMain.setUp(TestMain.java:12)
> at junit.framework.TestCase.runBare(TestCase.java:125)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
> org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:210)
> at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:135)
> at
> org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:122)
> at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:585)
> at
> org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225)
> at
> org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:747)
> Caused by: java.io.IOException: Class not found
> at org.objectweb.asm2.ClassReader.readClass(ClassReader.java:259)
> at org.objectweb.asm2.ClassReader.<init>(ClassReader.java:236)
> at org.objectweb.asm2.ClassReader.<init>(ClassReader.java:246)
> at mockit.Mockit.readClassFile(Mockit.java:225)
> It is not able to find the class, which was ok in the System.out run just
> before.
> If I do a mvn eclipse:eclipse and create an eclipse project, I can run the
> test class without any problems in Eclipse (with exactly tha same VM
> arguments as I use in the pom.xml)
> So I guess it is some issue with which classloader that loads the Mockit
> class when it is supplied as the instrumentation class via the -javaagent
> switch.
> Anybody experience any problems like this using the -javaagent switch?
> Any feedback would be greatly appreciated.
> regards,
> bdk
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira