gpt4 book ai didi

java - 使用 Powermock 时出现 NoClassDefFoundError

转载 作者:行者123 更新时间:2023-12-01 16:35:34 29 4
gpt4 key购买 nike

我正在尝试将 powermock 与 easymock 一起使用来测试私有(private)方法和静态方法。我已经从 GITHUB 下载了 jar 并将其依赖项添加到了 build.gradle 中,但是当我运行测试用例时,我不断收到 NoClassDefFoundError 错误。

以下是 gradle 中的堆栈跟踪和依赖项:

java.lang.NoClassDefFoundError: org/powermock/reflect/spi/ProxyFramework
at java.lang.ClassLoader.defineClass1(Native Method)
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$100(Unknown Source)
Caused by: java.lang.ClassNotFoundException:
org.powermock.reflect.spi.ProxyFramework
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)

testCompile group: 'org.powermock', name: 'powermock-core', version: '1.4.6'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '1.5.1'
testCompile group: 'org.easymock', name: 'easymock', version: '4.0.1'
testCompile group: 'cglib', name: 'cglib-nodep', version: '3.2.9'
testCompile group: 'org.hamcrest', name: 'hamcrest-core', version: '1.3'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.objenesis', name: 'objenesis', version: '3.0.1'
testCompile group: 'org.powermock', name: 'powermock-api-easymock', version: '2.0.2'
compile group: 'org.javassist', name: 'javassist', version: '3.24.0-GA'

最佳答案

我“认为”您没有指定依赖项的范围。我不知道如何在 Gradle 中做到这一点,但在 Maven 中,我们将“范围”测试“范围”添加到依赖项声明中。

关于java - 使用 Powermock 时出现 NoClassDefFoundError,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61954556/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com