【发布时间】:2016-03-31 11:42:28
【问题描述】:
我有以下设置来并行运行我的测试(对于 Selenium 测试):
[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);;
}
}
}
虽然我的 Jenkins 服务器上的测试结果报告只显示一个测试已经运行,但这工作正常。我想在报告中看到TestAllParallel() 运行的所有测试。
这可能吗?我在想,也许可以在运行时向 MSTest 添加一个方法作为测试。
【问题讨论】:
-
我认为 mstest 没有在运行时添加测试的方法。您可以为您的测试创建一个单独的 trx 文件(在您的方法中生成该文件),然后 Jenkins 中的 mstest 插件会认为它是从 MSTest 输出的。
-
也许您可以尝试检查测试代码本身的代码覆盖率(而不是被测试的代码)。虽然我不确定如何在 jenkins 和 mstest 中做到这一点。
-
为什么你自己执行所有的测试,而不是指示你的 Jenkins 服务器为你做呢?
-
@silver 我该怎么做?使用 Selenium 网格?
标签: c# selenium jenkins mstest