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.