使用 EasyMock 编写 Junit 时遇到 RunTimeError?
我正在为我的程序使用简单的模拟编写 junit。 测试方法
public static void doBeforeEachTestCase() {
private static FibanocciProg mock;
mock = EasyMock.createMock(FibanocciProg.class);
FibanocciProg testObject= new FibanocciProg();
EasyMock.expect(mock.recursionFib1(6)).andReturn(50);
EasyMock.replay(mock);
int actual = testObject.recursionFib1(6);
}
下面是我在 eclipse 中 EasyMock.createMock 时遇到的错误的 。我下载的用于轻松模拟的库是:- easymock-3.0、cglib-2.2.2、asm-4.0_RC2
Exception in thread "main" java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method visit.(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at net.sf.cglib.core.AbstractClassGenerator.<init>(AbstractClassGenerator.java:38)
at net.sf.cglib.core.KeyFactory$Generator.<init>(KeyFactory.java:127)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:112)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.easymock.internal.ClassProxyFactory.createEnhancer(ClassProxyFactory.java:259)
at org.easymock.internal.ClassProxyFactory.createProxy(ClassProxyFactory.java:174)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:60)
at org.easymock.EasyMock.createMock(EasyMock.java:104)
at TestMock.doBeforeEachTestCase(TestMock.java:19)
at TestMock.main(TestMock.java:13)
有任何指针吗?
i am writing the junit using easy mock for my program. Below is the test method
public static void doBeforeEachTestCase() {
private static FibanocciProg mock;
mock = EasyMock.createMock(FibanocciProg.class);
FibanocciProg testObject= new FibanocciProg();
EasyMock.expect(mock.recursionFib1(6)).andReturn(50);
EasyMock.replay(mock);
int actual = testObject.recursionFib1(6);
}
I am getting below error in eclipse while EasyMock.createMock. The libs i have downloaded for easy mock are:- easymock-3.0,cglib-2.2.2,asm-4.0_RC2
Exception in thread "main" java.lang.VerifyError: class net.sf.cglib.core.DebuggingClassWriter overrides final method visit.(IILjava/lang/String;Ljava/lang/String;Ljava/lang/String;[Ljava/lang/String;)V
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at net.sf.cglib.core.AbstractClassGenerator.<init>(AbstractClassGenerator.java:38)
at net.sf.cglib.core.KeyFactory$Generator.<init>(KeyFactory.java:127)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:112)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:108)
at net.sf.cglib.core.KeyFactory.create(KeyFactory.java:104)
at net.sf.cglib.proxy.Enhancer.<clinit>(Enhancer.java:69)
at org.easymock.internal.ClassProxyFactory.createEnhancer(ClassProxyFactory.java:259)
at org.easymock.internal.ClassProxyFactory.createProxy(ClassProxyFactory.java:174)
at org.easymock.internal.MocksControl.createMock(MocksControl.java:60)
at org.easymock.EasyMock.createMock(EasyMock.java:104)
at TestMock.doBeforeEachTestCase(TestMock.java:19)
at TestMock.main(TestMock.java:13)
Any Pointers?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的 Easymock 依赖项版本错误。查看EasyMock 3.0的maven pom ,依赖项是:
或 EasyMock 文档:
所以您使用的是版本 2.2.2 而不是 2.2。当您针对一个库进行编译但随后针对该库的另一版本执行时,通常会发生 java.lang.VerifyError 。
请参阅出现 java.lang.VerifyError 的原因的答案和java.lang.VerifyError
注意:要查找上述依赖项详细信息,您只需在 Maven 上搜索即可搜索。
You have the wrong version of the dependencies for Easymock. Looking at the maven pom for EasyMock 3.0, the dependencies are:
or the EasyMock documentation:
So you're using version 2.2.2 rather than 2.2. java.lang.VerifyError generally happens when you've compiled against one library but then are executing against another version of the library.
See the answers to Reasons of getting a java.lang.VerifyError and the javadoc for java.lang.VerifyError
Note: to find the above dependency details, you simply need to search on Maven Search.