.net - MSTest DataRowAttribute 字符串参数乱序
问题描述
我有一个使用 MSTest 的 .NET Framework 4.7.2 测试项目,方法如下:
[DataTestMethod]
[DataRow("https://www.example.com", "x", "y", "https://www.example.com?x=y")]
[DataRow("https://www.example.com/", "x", "y", "https://www.example.com?x=y")]
[DataRow("https://www.example.com/page.aspx", "x", "y", "https://www.example.com/page.aspx?x=y")]
[DataRow("https://www.example.com/page.aspx/", "x", "y", "https://www.example.com/page.aspx?x=y")]
[DataRow("https://www.example.com/page.aspx?k=v", "x", "y", "https://www.example.com/page.aspx?k=v&x=y")]
[DataRow("https://www.example.com/page.aspx?k=v&k2=v2", "x", "y", "https://www.example.com/page.aspx?k=v&k2=v2&x=y")]
[DataRow("https://www.example.com/Directory/page.aspx?k=v&k2=v2", "x", "y", "https://www.example.com/Directory/page.aspx?k=v&k2=v2&k=y")]
public void DoSomething___works(string url, string n, string v, string expected)
{
url.DoSomething(n, v).ShouldBe(expected); // using Shouldly nuget package
}
当我运行测试时,第 5 个成功并正常运行,但其他所有测试都失败了。有趣的是,它们失败了,因为来自DataRowAttribute
的参数以与预期不同的顺序分配给测试方法的参数。
例如,如果我调试第一个测试用例,这些是方法参数的值: | 参数 | 实际值 | 预期值 | | ----- | ------------- | --------------- | | 网址 | https://info.chromres.com?foo=bar | https://info.chromres.com | | n | https://info.chromres.com | x | | v | x | 是 | | 预期 | 是 | https://info.chromres.com?foo=bar |
所以看起来他们只是随机向右移动了一个位置。
为什么会发生这种情况?为什么它只会发生在大多数——但不是所有——的情况下?
有没有人见过这个?
解决方案
推荐阅读
- c# - 是否有更好的设计来公开您不想直接实现的基本接口?
- python - 在 Python 中使用日期时间以及如何从 Excel 导入
- android - 使用 OkHttp 自定义 SSL 固定
- sql - 分析sql死锁xml
- java - JavaFX LineChart 绘制红色区域
- php - 在不使用 action="" 的情况下发送 PHP 确认电子邮件联系表
- javascript - JS 检查日期在今天的 6 个月内
- c# - C# - 如何在属性或变量中分配泛型类型
- android - 无法将我的 android 设备连接到 android studio
- javascript - 为什么执行这个 Else 条件?