You can do it by creating N tasks, starting all of them and then waiting for them to finish. You can use Assert methods inside the tasks, when they fail an AssertionFailedException will be thrown and you can catch that on the parent thread easily when using async/await. I believe MsTest supports the async keyword for test methods from Visual Studio 2012 (or 2013). Something like this:
// no TestMethod attribute here
public Task TestMyWebMethodAsync()
{
return Task.Run(() =>
{
// add testing code here
Assert.AreEqual(expectedValue, actualValue);
});
}
[TestMethod]
public async void ParallelTest()
{
try {
const int TaskCount = 5;
var tasks = new Task[TaskCount];
for (int i = 0; i < TaskCount; i++)
{
tasks[i] = TestMyWebMethodAsync();
}
await Task.WhenAll(tasks);
// handle or rethrow the exceptions
} catch (AssertionFailedException exc) {
Assert.Fail("Failed!");
} catch (Exception genericExc) {
Assert.Fail("Exception!");
}
}
If you have the Premium or Ultimate version of Visual Studio then you can make this easier by creating load tests:
https://learn.microsoft.com/en-us/previous-versions/azure/devops/test/load-test/run-performance-tests-app-before-release