c# - 在不同节点下有多个同名测试
问题描述
我有两个不同的测试共享相同的数据:
[TestCaseSource(nameof(ProvideTestCases))]
public void SubtractSegmentsTests(IPolyline polyline, IPolyline toRemove, double tol, IGeometry expected)
{
GeometryTools.SubtractSegments(polyline, toRemove, tol, null);
AssertEqualPoints((IPointCollection) expected, (IPointCollection) polyline);
}
[TestCaseSource(nameof(ProvideTestCases))]
public void SubtractSegmentsTests_With_Esri(IPolyline polyline, IPolyline toRemove, double tol, IGeometry expected)
{
var actual = ((ITopologicalOperator)polyline).Difference(toRemove);
AssertEqualPoints((IPointCollection)expected, (IPointCollection)actual);
}
所以我想要实现的是测试两种不同的方式,如果两者都返回完全相同的结果。因此,两种测试方法都引用了完全相同的测试用例:
public IEnumerable<TestCaseData> ProvideTestCases()
{
yield return new TestCaseData(...).SetName("Test1");
}
当我使用 ReSharper 在 VS 中执行测试时,这非常有效。测试运行程序能够将属于的测试与属于的测试SubtractSegmentsTests
分开SubtractSegmentsTests_With_Esri
。
现在我从我的 Jenkins-Server 中运行这些测试:
call "C:\Program Files (x86)\NUnit.org\nunit-console\nunit3-console.exe" MySuT.dll --result:testresults/result.xml;format=nunit2
这里 NUnit 对同一节点下的所有测试进行排序 - testclass - 使得无法区分 call Test1
fromSubtractSegmentsTests
和Test1
from SubtractSegmentsTests_With_Esri
。
有没有办法在我的 CI 服务器上获得这种级别的聚合?
解决方案
好吧,重申一下对您来说可能已经很明显的事情,您的两个测试只有相同的名称,因为您给了它们相同的名称。:-)
一些跑步者认为名字是唯一的。为了处理不做这种假设的 NUnit,他们通常会添加一些前缀。NUnit 控制台运行程序对所有具有相同名称的测试感到满意,因为它们实际上是由(隐藏的)id 标识的。因此,NUnit 控制台不会费心以不同的方式显示它们,尽管如果有足够多的人询问它可以。
但是,NUnit 还使您能够在设置名称时使自己的名称独一无二。在这种情况下,您只需在设置名称的字符串中包含“{m}”,测试方法的名称将被使用。
有关设置名称的更多信息,请参阅https://github.com/nunit/docs/wiki/Template-Based-Test-Naming上的文档
推荐阅读
- php - 致命错误:未捕获的 SoapFault 异常:[WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from.......failed to load external entity
- python - vagrant up eos 完全冻结系统,无法启动 eos
- c++ - 如何将多个变量从主函数传递到其他函数C++
- terminal - glob 模式不会在 zsh 中的文件内扩展
- c++ - C ++中的简单属性访问不起作用
- python - 在python中递归生成列表的子集
- appium - uiautomator:创建临时文件以保存快照时出错
- .net-core - 将 xUnit 项目升级到 .NET Core 2.1.1
- excel - 从变量中定位列位置并传递给 .range"" 代码
- javascript - JavaScript `then` 和 Haskell `fmap` 一样吗?