【问题标题】:Getting error "Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found" in unit test but not in main program在单元测试中出现错误“Provider com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl not found”,但在主程序中没有
【发布时间】:2012-01-25 10:26:15
【问题描述】:

我正在用 C# 构建一个应用程序,它使用 com.gargoylesoftware.htmlunit.WebClient 来访问和检索网页中的信息。

我的应用程序在主项目中运行良好,但是当我尝试构建单元测试来测试项目类时,出现以下错误:

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 也会导致此错误。

我在主项目和包含单元测试的项目中都有项目引用 htmlunit-2.7、IKVM.OpenJDK.Core 和 IKVM.OpenJDK.XML.API。

是否需要额外的项目参考才能运行单元测试?什么可能导致此错误?

测试类使用Microsoft.VisualStudio.TestTools.UnitTesting;

【问题讨论】:

  • 凯蒂的答案解决了你的问题吗?

标签: c# unit-testing webclient htmlunit


【解决方案1】:

我最近在测试同一个库时遇到了同样的问题。我发现包含对 IKVM.OpenJDK.XML.Parse.dll 的引用解决了这个问题。

【讨论】:

    【解决方案2】:

    我遇到了类似的问题。

    似乎 com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderFactoryImpl 类未加载,因此工厂无法创建它。在调用工厂之前添加此行会强制加载程序集,然后工厂可以看到它并且一切都按预期工作......

    com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl s =   new  com.sun.org.apache.xerces.@internal.jaxp.SAXParserFactoryImpl();
    

    【讨论】:

    • 添加此代码工作正常。 VB.Net Dim s As com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl = New com.sun.org.apache.xerces.internal.jaxp.SAXParserFactoryImpl()
    猜你喜欢
    • 1970-01-01
    • 2021-01-12
    • 2020-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多