Junit Swing测试log4j程序时出现的问题
这几天一直在测试,操作系统是Solaris,用的是Junit,(真是烦啊,真看不出Unix哪里好,图形界面还不如Windows3.1,可能是我水平太低)。第一次写测试用例,好多东西也模模糊糊,昨天要测试的函数功能是用log4j输出日志,一如既往,写好测试用例,运行Junit,输入要测试的用例类名,点击Run按钮,结果发现下面的错误:
log4j:ERROR A "org.apache.log4j.RollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [junit.runner.TestCaseClassLoader <at> 1e903d5] whereas object of type
log4j:ERROR "org.apache.log4j.RollingFileAppender" was loaded by [sun.misc.Launcher$AppClassLoader <at> 12f6684].
log4j:ERROR Could not instantiate appender named "A1".
.......
刚开始我以为是properties文件的路径不对,换了好几个路径,还是一样,于是我打开Google,结果国内没有发现相关报道,全是英文,烦,只有硬着头皮看,无意中找到了这样一篇文章,我把URL也贴上吧
http://permalink.gmane.org/gmane.comp.jakarta.log4j.user/3545
下面有这样一段文字:
The junit swing test runner has a default option to reload classes everytime you click the "run" button. This is a good thing so you can avoid restarting the gui. The problem with log4j though, is that this is causing log4j to load the classes "org.apache.log4j.Appender" and "org.apache.log4j.ConsoleAppender" with different classloaders as seen in the error message. The Appender class seems to be loaded as a regular java class (probably via new), but the ConsoleAppender is being loaded by this special Thread Context Classloader. This Appender class is being loaded via this special junit class loader, "junit.runner.TestCaseClassLoader <at> a9255c". ConsoleAppender needs to be loaded by either the same classloader used to load the Appender class or a child of that classloader. It appears that log4j is using attempting to use a parent of the classloader used to load Appender here.
我看了一下大概的意思,本人英文太差,所以就不献丑翻译了,哪位英文好的花两分钟翻译一下,好让更多的人知道,不慎感激。上面文字中看得出老外用的是ConsoleAppender,我用的是文件输出的RollingFileAppender,应该是一样的道理。
于是我把Junit左边那个CheckBox(Reload classes every run)那个勾去掉,运行Run,一切OK。
log4j:ERROR A "org.apache.log4j.RollingFileAppender" object is not assignable to a "org.apache.log4j.Appender" variable.
log4j:ERROR The class "org.apache.log4j.Appender" was loaded by
log4j:ERROR [junit.runner.TestCaseClassLoader <at> 1e903d5] whereas object of type
log4j:ERROR "org.apache.log4j.RollingFileAppender" was loaded by [sun.misc.Launcher$AppClassLoader <at> 12f6684].
log4j:ERROR Could not instantiate appender named "A1".
.......
刚开始我以为是properties文件的路径不对,换了好几个路径,还是一样,于是我打开Google,结果国内没有发现相关报道,全是英文,烦,只有硬着头皮看,无意中找到了这样一篇文章,我把URL也贴上吧
http://permalink.gmane.org/gmane.comp.jakarta.log4j.user/3545
下面有这样一段文字:
The junit swing test runner has a default option to reload classes everytime you click the "run" button. This is a good thing so you can avoid restarting the gui. The problem with log4j though, is that this is causing log4j to load the classes "org.apache.log4j.Appender" and "org.apache.log4j.ConsoleAppender" with different classloaders as seen in the error message. The Appender class seems to be loaded as a regular java class (probably via new), but the ConsoleAppender is being loaded by this special Thread Context Classloader. This Appender class is being loaded via this special junit class loader, "junit.runner.TestCaseClassLoader <at> a9255c". ConsoleAppender needs to be loaded by either the same classloader used to load the Appender class or a child of that classloader. It appears that log4j is using attempting to use a parent of the classloader used to load Appender here.
我看了一下大概的意思,本人英文太差,所以就不献丑翻译了,哪位英文好的花两分钟翻译一下,好让更多的人知道,不慎感激。上面文字中看得出老外用的是ConsoleAppender,我用的是文件输出的RollingFileAppender,应该是一样的道理。
于是我把Junit左边那个CheckBox(Reload classes every run)那个勾去掉,运行Run,一切OK。
posted on 2006-07-19 09:36 gigikouyi 阅读(2727) 评论(0) 编辑 收藏 举报