1
Vote

Async test gets executed twice when used with the -b option

description

I noticed that if a test assembly contains async unit tests, all the async tests get executed twice, but counted as one test run. Here's a simple example:
    private static int i;

   [TestMethod]
    public void SyncTest()
    {
        i++;
        TestContext.WriteLine("SyncTest executing " + i);
    }

   [Asynchronous]
   [TestMethod]
    public void AsyncTest()
    {
        i++;
        TestContext.WriteLine("AsyncTest started " + i);
        this.EnqueueCallback(
            () =>
                {
                    TestContext.WriteLine("AsyncTest stopped " + i);
                    this.TestComplete();
                });
    }
if execute the tests with the -b option i get the following output:

StatLight - Version 1.6.4375
Copyright (C) 2009-2011 Jason Jarrett
All Rights Reserved.

Starting Test Run: 06.01.2014 16:37:31

MessageType=Debug
Message=AsyncTest started 1
Decorators:

MessageType=Debug
Message=AsyncTest stopped 1
Decorators:

MessageType=Debug
Message=AsyncTest started 2
Decorators:

MessageType=Debug
Message=AsyncTest stopped 2
Decorators:

MessageType=Debug
Message=SyncTest executing 3
Decorators:

*************** Summary ********************

Total : 2
Successful : 2
Failed : 0
Ignored : 0
Completion End : 06.01.2014 16:37:32
Duration : 00:00:01.2053036

If i run the same test without -b option the output is as follows:

StatLight - Version 1.6.4375
Copyright (C) 2009-2011 Jason Jarrett
All Rights Reserved.

Starting Test Run: 06.01.2014 16:41:29

MessageType=Debug
Message=AsyncTest started 1
Decorators:

MessageType=Debug
Message=AsyncTest stopped 1
Decorators:

MessageType=Debug
Message=SyncTest executing 2
Decorators:

*************** Summary ********************

Total : 2
Successful : 2
Failed : 0
Ignored : 0
Completion End : 06.01.2014 16:41:30
Duration : 00:00:01.1039629

Is this a know problem in StatLight?

Thanks, Georg

comments

staxmanade wrote Jan 8, 2014 at 4:56 PM

Interesting...

Possibly related to http://statlight.codeplex.com/workitem/13309 or http://statlight.codeplex.com/workitem/11906. I recall this happening with the first test in the suite, but not all of the tests... I believe StatLight has some hackey code to hide that from the output.

Unfortunately I don't have a solution for you. My theory is it's a bug in the Microsoft Testing framework. Unless you can pinpoint it inside StatLight, I'm not sure what we can do in this case...

Good luck.