我正在使用带有 powermock-easymock-1.5-full.jar 的powermock。发生以下异常。
这些是我在classpath中的所有罐子。并从http://code.google.com/p/powermock/downloads/detail?name=powermock-easymock-testng-1.5.zip&can=2&q=
下载为powermock软件包
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)
请帮帮我
答案 0 :(得分:6)
这对我有用:
@PowerMockIgnore({"javax.xml.*", "org.xml.sax.*", "org.w3c.dom.*", "org.springframework.context.*", "org.apache.log4j.*"})
答案 1 :(得分:5)
如果这是与PowerMock相关的问题,那么您可以尝试使用以下命令注释测试类:
@PowerMockIgnore({"javax.xml.parsers.*", "com.sun.org.apache.xerces.internal.jaxp.*"})
答案 2 :(得分:0)
您可以忽略log4j。。我和jptool logger有同样的问题。我已经通过忽略而解决了问题 这是我的代码 @PowerMockIgnore({" jptools "})
答案 3 :(得分:0)
这是一个PowerMock问题,我遇到了这个错误:
java.lang.ClassCastException: class sun.security.provider.ConfigFile
您可以使用此注释解决,尝试使用以下命令注释测试类:
@PowerMockIgnore({"javax.management.*", "java.lang.*", "javax.security.*" })
答案 4 :(得分:0)
您可以在 configuration.properties
中创建包含内容的 test/resources/org/powermock/extensions/
文件:
powermock.global-ignore=org.apache.xerces.*,javax.xml.parsers.*,org.xml.sax.*
注意:属性值中逗号分隔,不能有空格,否则无效! 包列表取决于项目的依赖项。
PowerMock 配置 here。