Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Parallel] Console/Debug traces + Log.LogMessage are not associated with the right test case #321

Closed
AbhitejJohn opened this issue Nov 28, 2017 · 2 comments

Comments

@AbhitejJohn
Copy link
Contributor

Description

Currently all the logging does not get associated with the right test case because the underlying implementation Console.SetOut or the log message listener are global listeners and not thread specific. There isn't a workaround for this today.

@sea1jxr
Copy link
Member

sea1jxr commented Jun 7, 2018

@cltshivash this really is a bug, it makes investigating test failures in automated runs impossible using logs. I love the parallel feature, but this bug makes it hard to use in production CI/CD scenarios.

@cltshivash cltshivash added the bug label Jun 15, 2018
@cltshivash
Copy link
Contributor

cltshivash commented Jun 15, 2018

@sea1jxr Console.Writeline is a static instance and will not be thread safe. Using TestContext will ensure that the output for a test only has the relevant logs. Sample below

using ExecutionScope = Microsoft.VisualStudio.TestTools.UnitTesting.ExecutionScope;

[assembly: Parallelize(Workers = 2, Scope = ExecutionScope.MethodLevel)]

namespace UnitTestProject1
{

    [TestClass]

    public class UnitTest1
    {
        public TestContext TestContext { get; set; }

        [TestMethod]
        public async Task TestMethod1()
        {
            for (int index = 0; index < 100; ++index)
            {
                TestContext.WriteLine("Log From TestMethod...1");
                await Task.Delay(100);
            }
        }

        [TestMethod]
        public async Task TestMethod2()
        {
            for (int index = 0; index < 100; ++index)
            {
                TestContext.WriteLine("Log From TestMethod...2");
                await Task.Delay(100);
            }
        }
    }
}

singhsarab pushed a commit to singhsarab/testfx that referenced this issue Apr 8, 2019
* Fix vsmanproj to point to right json
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants