关闭

项目添加Maven支持后,单元测试报异常解决

发表于:2013-7-25 11:00

字体: | 上一篇 | 下一篇 | 我要投稿

 作者:wangjunjun2008    来源:51Testing软件测试网采编

  项目添加Maven支持后,运行JUnit单元测试,出现一下错误:

ERROR in ch.qos.logback.core.joran.action.AppenderAction - Could not create an Appender of type
[com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender]. ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type

com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender
 at ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender
 at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)
 at  ......(省略打印信息)
 at  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file javax/mail/internet/AddressException
 at  at java.lang.ClassLoader.defineClass1(Native Method)
 at  .....(省略打印信息)
 at  ... 41 common frames omitted

ERROR in ch.qos.logback.core.joran.spi.Interpreter@192:115 - ActionException in Action for tag [appender] ch.qos.logback.core.joran.spi.ActionException:

ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender
 at ch.qos.logback.core.joran.spi.ActionException: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type

com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender
 at  at ch.qos.logback.core.joran.action.AppenderAction.begin(AppenderAction.java:82)
 at  ......(省略打印信息)
 at  at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: ch.qos.logback.core.util.DynamicClassLoadingException: Failed to instantiate type com.travelsky.tdp.pkgStock.integration.logback.appender.mail.SMTPAppender
 at  at ch.qos.logback.core.util.OptionHelper.instantiateByClassName(OptionHelper.java:54)
 at  ... 39 common frames omitted
Caused by: java.lang.ClassFormatError: Absent Code attribute in method that is not native or abstract in class file <SPAN style="COLOR: #ff0000"><STRONG>javax/mail/internet/<SPAN style="COLOR: #ff0000">Ad</SPAN>dressException</STRONG></SPAN>
 at  at java.lang.ClassLoader.defineClass1(Native Method)
 at  .....(省略打印信息)
 at  ... 41 common frames omitted

  单元测试失败,查找原因,发现如下问题:

  1、Maven依赖中使用的 javeee.jar 版本较高,里面包含了 mail相关的接口,和 mail.jar 相冲突;

  2、javaee.jar 中包含了 mail相关接口的 实现类;

  3、MyEclipse自带的javaee.jar 版本和 MyEclipse本身的版本有关:MyEclipse6.5自带的javaee.jar 中不包含mail相关的接口,而MyEclipse8.0自带的javaee.jar中包含了mail相关的接口,同时包含了接口的实现;

  4、项目中直接用到了mail.jar中的类和方法;

  此bug出现的原因是由于类冲突,因此去掉冲突的类即可;但是应该怎么选择呢?

21/212>
《2023软件测试行业现状调查报告》独家发布~

关注51Testing

联系我们

快捷面板 站点地图 联系我们 广告服务 关于我们 站长统计 发展历程

法律顾问:上海兰迪律师事务所 项棋律师
版权所有 上海博为峰软件技术股份有限公司 Copyright©51testing.com 2003-2024
投诉及意见反馈:webmaster@51testing.com; 业务联系:service@51testing.com 021-64471599-8017

沪ICP备05003035号

沪公网安备 31010102002173号