I have the following setup to run my tests in parallel (for Selenium tests):
[TestClass]
public class ParallelTests
{
[TestMethod]
public void TestAllParallel()
{
var testActions = Assembly.GetExecutingAssembly().GetTypes()
.Where(t =>
t.GetCustomAttribute<CompilerGeneratedAttribute>() == null &&
t.GetCustomAttribute<TestClassAttribute>() != null)
.Select(t => new Action(() => RunTest(t)))
.ToArray();
System.Threading.Tasks.Parallel.Invoke(testActions);
}
private static void RunTest(Type test)
{
var instance = Activator.CreateInstance(test);
ExecuteTestMethods(instance);
}
private static void ExecuteTestMethods(object instance)
{
var testMethods = instance.GetType().GetMethods()
.Where(m =>
m.GetCustomAttribute<TestMethodAttribute>(false) != null &&
m.GetCustomAttribute<IgnoreAttribute>(false) == null)
.ToArray();
foreach (var methodInfo in testMethods)
{
methodInfo.Invoke(instance, null);;
}
}
}
This works fine although the test result report on my Jenkins server only shows that one test has run. I would like to see in the report all the tests that has been run by TestAllParallel()
.
Is this possible to do? I'm thinking that perhaps it would be possible to add a method as a test to MSTest during runtime.