使用EasyMock编写Junit时获取RunTimeError?

时间:2011-10-01 13:13:11

标签: java junit

我正在使用easy mock为我的程序编写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);

 }

在EasyMock.createMock中,我在eclipse中遇到错误。我已经下载的易于模拟的库是: - 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)

任何指针?

1 个答案:

答案 0 :(得分:2)

您有错误的Easymock依赖项版本。查看maven pom for EasyMock 3.0,依赖项是:

  <dependency>
    <groupId>cglib</groupId>
    <artifactId>cglib-nodep</artifactId>
    <version>2.2</version>
  </dependency>
  <dependency>
    <groupId>org.objenesis</groupId>
    <artifactId>objenesis</artifactId>
    <version>1.2</version>
  </dependency>

EasyMock documentation

  

要求

     
      
  • EasyMock仅适用于Java 1.5.0及更高版本。
  •   
  • cglib(2.2)和Objenesis(1.2)必须在类路径中才能执行   类嘲笑
  •   

所以你使用的是2.2.2而不是2.2。 java.lang.VerifyError通常在您针对一个库编译但随后针对该库的另一个版本执行时发生。

查看Reasons of getting a java.lang.VerifyError的答案和java.lang.VerifyError

的javadoc

注意:要查找上述依赖项详细信息,只需搜索Maven Search