Skip to content

Instantly share code, notes, and snippets.

@mattanja
Created October 16, 2012 13:20
Show Gist options
  • Save mattanja/3899236 to your computer and use it in GitHub Desktop.
Save mattanja/3899236 to your computer and use it in GitHub Desktop.
Using log4net TestContextAppender
namespace MyTests
{
[TestClass()]
public class IParameterServiceTest
{
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
}
/// <summary>
/// Create logger configuration.
/// </summary>
[TestInitialize()]
public void MyTestInitialize()
{
log4net.LogManager.ResetConfiguration();
log4net.Config.BasicConfigurator.Configure(new TestContextAppender(this.TestContext));
}
///<summary>
/// A test method testing some service method.
///</summary>
[TestMethod()]
public void AssignDepositaryBankTest()
{
// [...] test the service that may be logging warnings or errors
// Make shure no warnings or errors occured
TestContextAppender.AssertDefaults(this.TestContext);
}
[...] Other tests [...]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment