得到错误“未找到提供者com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"在单元测试中,但不在主程序中 [英] Getting error "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found" in unit test but not in main program
问题描述
我正在用C#构建一个应用程序,该应用程序使用com.gargoylesoftware.htmlunit.WebClient访问和检索网页信息.
I am building an application in C# which uses com.gargoylesoftware.htmlunit.WebClient to access and retrieve information from webpages.
我的应用程序在主项目中运行良好,但是当我尝试构建单元测试以测试项目类时,出现以下错误:
My application runs fine from the main project but when I try to build unit tests to test the project classes I get the following error:
FactoryConfigurationError
Message "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found"
Source "IKVM.OpenJDK.XML.API" string
StackTrace " at javax.xml.parsers.DocumentBuilderFactory.newInstance()
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration(Reader configurationReader)
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.loadConfiguration()
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration..ctor(BrowserVersion )
at com.gargoylesoftware.htmlunit.javascript.configuration.JavaScriptConfiguration.getInstance(BrowserVersion browserVersion)
at com.gargoylesoftware.htmlunit.javascript.JavaScriptEngine..ctor(WebClient webClient)
at com.gargoylesoftware.htmlunit.WebClient.init(BrowserVersion , ProxyConfig )
at com.gargoylesoftware.htmlunit.WebClient..ctor(BrowserVersion browserVersion)
at com.gargoylesoftware.htmlunit.WebClient..ctor()
at GWT.HeadlessBrowser..ctor() in C:\\hg\\EXE\\GWT\\HeadlessBrowser.cs:line 57
at TestGWT.ProgramTest.TestLogInProcessForGWT() in C:\\hg\\TestGWT\\ProgramTest.cs:line 115"
尝试在单元测试类中创建HtmlUnit WebClient也会导致此错误.
Trying to create a HtmlUnit WebClient in the unit test class causes this error as well.
在主项目和包含单元测试的项目中,我都有项目引用htmlunit-2.7,IKVM.OpenJDK.Core和IKVM.OpenJDK.XML.API.
I have project references htmlunit-2.7, IKVM.OpenJDK.Core, and IKVM.OpenJDK.XML.API in both the main project and the project containing the unit test.
我需要其他项目参考来运行单元测试吗?可能是什么原因导致此错误?
Do I need an additional project reference for the unit test to run? What might be causing this error?
测试类使用Microsoft.VisualStudio.TestTools.UnitTesting;
The test class uses Microsoft.VisualStudio.TestTools.UnitTesting;
推荐答案
我最近在测试同一库时遇到了同一问题.我发现添加对IKVM.OpenJDK.XML.Parse.dll的引用可以解决此问题.
I ran into the same issue just recently while testing the same library. I found that including a reference to IKVM.OpenJDK.XML.Parse.dll solved the issue.
这篇关于得到错误“未找到提供者com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl"在单元测试中,但不在主程序中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!