我有這個簡單的測試:單元測試記錄(或運行)多次
protected readonly ILog logger = LogManager.GetLogger(MethodBase.GetCurrentMethod().ReflectedType);
private static int count = 0;
[Test]
public void TestConfiguredSuccessfully()
{
logger.Debug("in test method" + count++);
}
log4net的設置是這樣的:
[TestFixtureSetUp]
public void SetUp()
{
log4net.Config.BasicConfigurator.Configure();
}
的問題是,如果我運行這個測試中NUnit的一次,我得到的輸出(如預期):
1742 [TestRunnerThread] DEBUG Tests.TestSomthing (null) - in test method0
但是,如果我在nUnit.exe按再次運行(或更多)我得到以下幾點:
1742 [TestRunnerThread] DEBUG Tests.TestSomthing (null) - in test method1
1742 [TestRunnerThread] DEBUG Tests.TestSomthing (null) - in test method1
等等(如果我運行它5次,我會得到5個重複行)。現在,如果我從reSharper單獨運行相同的測試,則輸出很好,不會重複。但是,如果我在同一班的其他測試中進行此測試,則輸出會重複三次。
我完全困惑。這到底是怎麼回事?
明天試試你的解決方案。我最終只是向'Configure()'方法提供'新的ConsoleAppender()'並且它工作。 – 2010-06-15 10:01:58