问题
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