测试套装在日食中运行得很好。但是,当我们尝试使用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
在玩了上一个例子一段时间之后,我们开始似乎只是将问题推迟到稍后被其他一些代码拾取。我们一直在玩我们如何装载罐子,以便我们可以解决任何冲突,但到目前为止我们还没有运气。任何人可以提供的帮助都很棒。
答案 0 :(得分:1)
我遇到了类似的问题。对我有用的是在junit任务上设置fork="true"
。