Problems in JUnit swing testing log4j Program

Source: Internet
Author: User
I have been testing these days. The operating system is Solaris and JUnit is used, probably because my level is too low ). The first time I wrote a test case, many things were also vague. The function to be tested yesterday was to use log4j to output logs. As always, I wrote test cases, run JUnit, and input the name of the test case class, click the run button and the following error is found:

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
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 cocould not instantiate appender named "A1 ".
.......

At the beginning, I thought the path of the properties file was incorrect. I changed several paths to the same path, so I opened Google. As a result, no domestic reports were found. They were all in English, I found such an article by looking at it with a hard head. Article I can also paste the URL.
Http://permalink.gmane.org/gmane.comp.jakarta.log4j.user/3545
Below is a text like this:
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.
I looked at the approximate meaning. My English is too bad, so I will not provide ugly translation. Which of the following can take two minutes to translate, so that more people can know and be grateful. In the above text, we can see that foreigners use consoleappender. I use rollingfileappender for file output. It should be the same.

So I removed the checkbox (reload classes every run) on the left of JUnit and Run. Everything is OK.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.