使用 EasyMock 编写 Junit 时遇到 RunTimeError?

发布于 2024-12-07 07:09:21 字数 2203 浏览 1 评论 0原文

我正在为我的程序使用简单的模拟编写 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

盗心人 2024-12-14 07:09:21

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

  <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 文档

要求

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

所以您使用的是版本 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:

  <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>

or the EasyMock documentation:

Requirements

  • EasyMock only works with Java 1.5.0 and above.
  • cglib (2.2) and Objenesis (1.2) must be in the classpath to perform
    class mocking

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文