1

测试服在eclipse中运行得很好。但是,当我们尝试使用 ANT 运行套装时,它会引发以下错误:

 Warning: Caught exception attempting to use SAX to load a SAX XMLReader
 Warning: Exception was: java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
 Warning: I will print the stack trace then carry on using the default SAX parser
 java.lang.ClassCastException: org.apache.xerces.parsers.SAXParser cannot be cast to org.xml.sax.XMLReader
     at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:199)
     at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150)
     at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83)
     at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894)
     at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715)
     at org.dom4j.io.SAXReader.read(SAXReader.java:435)
     at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1481)
     at org.hibernate.cfg.Configuration.configure(Configuration.java:1425)

正如网上许多人所建议的那样,我们试图忽略这些类,如下所示:

@PrepareForTest({MessageUtils.class, FacesUtils.class})
@PowerMockIgnore( { "com.sun.org.apache.xerces.*", "org.dom4j.*", "org.xml.sax.*" })
public class FooTests extends PowerMockTestCase {}

这并没有解决问题,我们开始收到此错误:

java.lang.ExceptionInInitializerError
    at com.magnus.newpack.dao.common.SessionManager.<clinit>(SessionManager.java:19)
    at com.magnus.newpack.dao.common.DAOBase.getSession(DAOBase.java:174)
    at com.magnus.newpack.dao.common.DAOBase.beginTransaction(DAOBase.java:63)
    at com.magnus.newpack.dao.PackagesDAO.getPackages(PackagesDAO.java:59)
    at com.magnus.newpack.managers.CreateNewUserManager.getPackages(CreateNewUserManager.java:23)
    at com.magnus.webapp.action.admin.createUserPage.clearValues(createUserPage.java:181)
    at com.magnus.webapp.action.admin.createUserPage.<init>(createUserPage.java:130)
    at com.magnus.service.CreateUserServiceClass.<init>(CreateUserServiceClass.java:36)
    at com.magnus.service.CreateUserServiceErrorsTests.testCreateUserNoNameNoFacesContext(CreateUserServiceErrorsTests.java:79)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80)
    at org.testng.internal.Invoker.invokeMethod(Invoker.java:691)
    at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:883)
    at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1208)
    at org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127)
    at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111)
    at org.testng.TestRunner.privateRun(TestRunner.java:758)
    at org.testng.TestRunner.run(TestRunner.java:613)
    at org.testng.SuiteRunner.runTest(SuiteRunner.java:334)
    at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329)
    at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291)
    at org.testng.SuiteRunner.run(SuiteRunner.java:240)
    at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53)
    at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87)
    at org.testng.TestNG.runSuitesSequentially(TestNG.java:1137)
    at org.testng.TestNG.runSuitesLocally(TestNG.java:1062)
    at org.testng.TestNG.run(TestNG.java:974)
    at org.testng.TestNG.privateMain(TestNG.java:1282)
    at org.testng.TestNG.main(TestNG.java:1246)
Caused by: org.hibernate.HibernateException: Could not instantiate dialect class
    at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:84)
    at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:42)
    at org.hibernate.cfg.SettingsFactory.determineDialect(SettingsFactory.java:409)
    at org.hibernate.cfg.SettingsFactory.buildSettings(SettingsFactory.java:119)
    at org.hibernate.cfg.Configuration.buildSettings(Configuration.java:2006)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1289)
    at com.magnus.newpack.dao.common.SessionManager.<clinit>(SessionManager.java:14)
    ... 31 more
Caused by: java.lang.ClassCastException: org.hibernate.dialect.MySQLDialect cannot be cast to org.hibernate.dialect.Dialect
    at org.hibernate.dialect.DialectFactory.buildDialect(DialectFactory.java:78)
    ... 37 more

在对前面的示例进行了一段时间的尝试之后,似乎我们只是在将问题推到后面,以便稍后由其他代码处理。我们也一直在研究如何加载罐子,以便我们可以解决任何冲突,但到目前为止我们还没有运气。有人可以提供的任何帮助都会很棒。

4

1 回答 1

1

我有类似的问题。对我有用的是设置fork="true"junit任务。

于 2012-04-06T00:10:30.803 回答