Last active
April 8, 2022 05:57
-
-
Save nohwnd/2936753d94301d7991059660d1d63a8a to your computer and use it in GitHub Desktop.
MSTest parallel output demo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Diagnostics; | |
using Microsoft.VisualStudio.TestTools.UnitTesting; | |
[assembly: Parallelize(Workers = 0, Scope = ExecutionScope.MethodLevel)] | |
namespace mstest; | |
[TestClass] | |
public class UnitTest1 | |
{ | |
static bool Flag1 = false; | |
static bool Flag2 = false; | |
static bool Flag3 = false; | |
[TestMethod] | |
public void TestMethod1() | |
{ | |
Console.WriteLine("TestMethod1"); | |
Flag1 = true; | |
while (!Flag2) { } | |
Console.WriteLine("TestMethod1"); | |
while (!Flag3) { } | |
Console.WriteLine("TestMethod1"); | |
Console.Error.WriteLine("ERRRRRR!"); | |
Trace.WriteLine("Tracing"); | |
Debug.WriteLine("Debugging"); | |
} | |
[TestMethod] | |
public void TestMethod2() | |
{ | |
Console.WriteLine("TestMethod2"); | |
while (!Flag1) { } | |
Console.WriteLine("TestMethod2"); | |
Flag2 = true; | |
while (!Flag3) { } | |
Console.WriteLine("TestMethod2"); | |
} | |
[TestMethod] | |
public async Task TestMethod3() | |
{ | |
Console.WriteLine("TestMethod3"); | |
while (!Flag1) { } | |
Console.WriteLine("TestMethod3"); | |
while (!Flag2) { } | |
FastChildMethod(); | |
await SlowChildMethod(); | |
Flag3 = true; | |
Console.WriteLine("TestMethod3"); | |
} | |
public async Task SlowChildMethod() | |
{ | |
await Task.Delay(1000); | |
Console.WriteLine("I am slow!"); | |
} | |
public async Task FastChildMethod() | |
{ | |
await Task.Delay(100); | |
Console.WriteLine("I am fast!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment