How to configure Log4net in unit tests

Source: Internet
Author: User

As a result, there is basically no requirement for logging in unit tests, which is determined by the positioning of the unit tests.

Because the idea of unit testing is for small pieces of code testing, logic clear, if the test run does not pass, simple debugging, you can easily troubleshoot the problem. But unit testing is also a handy starter. You can never debug any code, you want me to start a Windows or Web project, it is too cumbersome, and the larger the project, the longer the boot time. In cases where unit tests are used as initiators, there is a need to use log4net.

Go to the Chase

How to configure log4net in a unit test project:

1. Add the log4net configuration file

The focus here is not on the contents of the configuration file, but on the name of the configuration file.

    • If the test project name is a, then the name of the configuration file should be A.dll.config

    • Mail profile-Properties, change the attribute "copy to output Directory" to "Copy Alwasy"

2. Modify the Assembly.cs file

At the end of the file, add the following line of code

true)]
3. Define global startup in unit test, execute log4net load configuration file
[AssemblyInitialize]  Public Static void AssemblyInitialize (TestContext context) {   log4net. Config.XmlConfigurator.Configure ();}

How to configure log4net in the unit test, the skill is these, hoped can help to have this request the blog garden Friend.

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.