lundi 30 mai 2016

Owin TestServer logs multiple times while testing - how can I fix this?

I'm trying to write unit tests for an OWIN service, but any log statements in my tests start duplicating once I run the tests all at once and really make the log output on the build server useless due to all the noise. I've distilled the problem down to a very simple repro:

[TestFixture]
public class ServerTest
{
    [Test]
    public void LogOnce()
    {
        using (TestServer.Create(app => { }))
        {
            Debug.WriteLine("Log once");
        }
    }

    [Test]
    public void LogTwice()
    {
        using (TestServer.Create(app => { }))
        {
            Debug.WriteLine("Log twice");
        }
    }
}

If I run one test at a time I get the expected output:

=> ServerTest.LogOnce
Log once

=> ServerTest.LogTwice
Log twice

If I run the tests all at once I get:

=> ServerTest.LogOnce
Log once

=> ServerTest.LogTwice
Log twice
Log twice

Initializing the TestServer once will solve the problem, but I am looking for a solution that allows me to continue instantiating as many TestServer instances as I choose.

Aucun commentaire:

Enregistrer un commentaire