VerifyError while JUnit test involving Document and DocumentBuilder

左心房为你撑大大i 提交于 2020-01-16 12:35:08

问题



MyClass

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

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

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;

回答1:


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.



来源:https://stackoverflow.com/questions/48560458/verifyerror-while-junit-test-involving-document-and-documentbuilder

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!