涉及Document和DocumentBuilder的JUnit测试时,VerifyError [英] VerifyError while JUnit test involving Document and DocumentBuilder

查看:91
本文介绍了涉及Document和DocumentBuilder的JUnit测试时,VerifyError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

MyClass

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = null;
db = dbf.newDocumentBuilder(); //java.lang.verifyError here
Document doc = db.newDocument();

MyClassTest

MyClassTest

documentBuilderFactory = PowerMockito.mock(DocumentBuilderFactory.class);
PowerMockito.mockStatic(DocumentBuilderFactory.class);  
PowerMockito.when(DocumentBuilderFactory.newInstance()).thenReturn(documentBuilderFactory);
document = PowerMockito.mock(Document.class);
//documentBuilder = PowerMockito.mock(DocumentBuilder.class);
//PowerMockito.when(documentBuilder.newDocument()).thenReturn(document);

当我从MyClassTest中删除注释部分时,VerifyError位于测试类的最后一行.任何想法如何解决这个问题?我正在附加错误的堆栈跟踪.

When I'm removing the comment section from MyClassTest, the VerifyError comes in the last line of the test class. Any Idea how to solve this issue? I'm attaching the stack trace of the error.

java.lang.VerifyError: javax/xml/parsers/DocumentBuilder.newDocument()Lorg/w3c/dom/Document;

推荐答案

java.lang.VerifyError可能是针对与运行时使用的库不同的库进行编译的结果.

java.lang.VerifyError can be the result when you have compiled against a different library than you are using at runtime.

似乎您有类路径问题.解决该问题的解决方法.确保所有地方都有相同版本的罐子.

It seems you have classpath issues. Fixing that should solve the issue. Make sure everywhere you have same version of jars.

这篇关于涉及Document和DocumentBuilder的JUnit测试时,VerifyError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆