9

我正在使用 powermock 和powermock-easymock-1.5-full.jar。发生以下异常。

这些是我的类路径中的所有 jar。并从http://code.google.com/p/powermock/downloads/detail?name=powermock-easymock-testng-1.5.zip&can=2&q=下载为 powermock 包

  1. easymock-3.1.jar
  2. javassist-3.17.1-GA.jar
  3. jcommander-1.27.jar
  4. objenesis-1.2.jar
  5. snakeyaml-1.6.jar
  6. testng-6.8.jar
  7. bsh-2.0b4.jar
  8. cglib-nodep-2.2.2.jar
  9. powermock-easymock-1.5-full.jar

    java.lang.ClassCastException: com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
    at javax.xml.parsers.DocumentBuilderFactory.newInstance(Unknown Source)
    at com.eibus.localization.message.MessageSet._tryGetMessageText(MessageSet.java:268)
    at com.eibus.localization.message.Message._tryGetMessage(Message.java:135)
    at com.eibus.localization.message.Message.getMessage(Message.java:110)
    at com.eibus.localization.message.Message.getMessageWithLocaleFallBack(Message.java:155)
    at com.eibus.localization.StringFormatter.getMessageWithFallBack(StringFormatter.java:141)
    at com.eibus.localization.StringFormatter.format(StringFormatter.java:43)
    at com.eibus.localization.LocalizableComposite.getMessage(LocalizableComposite.java:42)
    at com.eibus.localization.exception.LocalizableException.getMessage(LocalizableException.java:168)
    at com.eibus.localization.exception.LocalizableException.getLocalizedMessage(LocalizableException.java:130)
    at java.lang.Throwable.toString(Throwable.java:479)
    at java.lang.String.valueOf(Unknown Source)
    at java.io.PrintWriter.println(Unknown Source)
    at java.lang.Throwable$WrappedPrintWriter.println(Unknown Source)
    at java.lang.Throwable.printStackTrace(Throwable.java:654)
    at java.lang.Throwable.printStackTrace(Throwable.java:720)
    at org.junit.runner.notification.Failure.getTrace(Failure.java:67)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestListener.testFailure(JUnit4TestListener.java:68)
    at org.junit.runner.notification.RunNotifier$4.notifyListener(RunNotifier.java:100)
    at org.junit.runner.notification.RunNotifier$SafeNotifier.run(RunNotifier.java:41)
    at org.junit.runner.notification.RunNotifier.fireTestFailure(RunNotifier.java:97)
    at org.junit.internal.runners.MethodRoadie.addFailure(MethodRoadie.java:154)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.handleException(PowerMockJUnit44RunnerDelegateImpl.java:359)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit49RunnerDelegateImpl$PowerMockJUnit49MethodRunner.executeTest(PowerMockJUnit49RunnerDelegateImpl.java:93)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$PowerMockJUnit44MethodRunner.runBeforesThenTestThenAfters(PowerMockJUnit44RunnerDelegateImpl.java:284)
    at org.junit.internal.runners.MethodRoadie.runTest(MethodRoadie.java:84)
    at org.junit.internal.runners.MethodRoadie.run(MethodRoadie.java:49)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.invokeTestMethod(PowerMockJUnit44RunnerDelegateImpl.java:209)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.runMethods(PowerMockJUnit44RunnerDelegateImpl.java:148)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl$1.run(PowerMockJUnit44RunnerDelegateImpl.java:122)
    at org.junit.internal.runners.ClassRoadie.runUnprotected(ClassRoadie.java:34)
    at org.junit.internal.runners.ClassRoadie.runProtected(ClassRoadie.java:44)
    at org.powermock.modules.junit4.internal.impl.PowerMockJUnit44RunnerDelegateImpl.run(PowerMockJUnit44RunnerDelegateImpl.java:120)
    at org.powermock.modules.junit4.common.internal.impl.JUnit4TestSuiteChunkerImpl.run(JUnit4TestSuiteChunkerImpl.java:101)
    at org.powermock.modules.junit4.common.internal.impl.AbstractCommonPowerMockRunner.run(AbstractCommonPowerMockRunner.java:53)
    at org.powermock.modules.junit4.PowerMockRunner.run(PowerMockRunner.java:53)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

请帮我

4

5 回答 5

15

这是对我有用的东西:

@PowerMockIgnore({"javax.xml.*", "org.xml.sax.*", "org.w3c.dom.*",  "org.springframework.context.*", "org.apache.log4j.*"}) 
于 2015-05-18T08:52:44.527 回答
5

如果这是与 PowerMock 相关的问题,那么您可以尝试使用以下命令注释您的测试类:

@PowerMockIgnore({"javax.xml.parsers.*", "com.sun.org.apache.xerces.internal.jaxp.*"})
于 2013-02-01T19:28:26.803 回答
0

这是一个 PowerMock 问题,我有这个错误:

java.lang.ClassCastException: class sun.security.provider.ConfigFile

您可以使用此注释解决,请尝试使用以下方法注释您的测试类:

@PowerMockIgnore({"javax.management.*", "java.lang.*", "javax.security.*" })
于 2018-05-28T09:08:31.273 回答
0

您可以忽略 log4j。. 我对 jptool 记录器有同样的问题。我已经通过忽略它解决了这是我的代码@PowerMockIgnore({"jptools. "})

于 2018-03-19T03:02:41.673 回答
0

您可以创建一个包含内容的configuration.properties文件test/resources/org/powermock/extensions/

powermock.global-ignore=org.apache.xerces.*,javax.xml.parsers.*,org.xml.sax.*

注意:属性值中逗号分隔,不能有空格,否则无效!包列表取决于项目的依赖项。

PowerMock 配置在这里

于 2021-04-05T13:42:20.950 回答