【发布时间】:2021-06-09 17:15:15
【问题描述】:
一般来说,我对 C# 和 MSTest 有点陌生,我正在尝试使用 DynamicData 属性进行参数化单元测试,看起来参数在运行时正在交换,这是我的测试的 sn-p:
[TestClass]
public class SampleTest
{
private TestContext testContextInstance;
public TestContext TestContext
{
get { return testContextInstance; }
set { testContextInstance = value; }
}
private static IEnumerable<object[]> ReusableTestData =>
new List<object[]> {
new object[] { 1, 2, 3 },
new object[] { 4, 5, 6 }
};
[DataTestMethod]
[DynamicData(nameof(ReusableTestData))]
public void Test1(int param1, int param2, int param3 )
{
TestContext.WriteLine($"{param1} {param2} {param3}");
}
在控制台上,在第一个测试中我得到:
1 2 3
在第二次测试中我得到:
6 5 4
我在这里缺少一些配置吗?还是关于 MSTest 及其参数化测试的已知问题?
【问题讨论】:
-
我无法重现该输出。我的
1 2 3and4 5 6using your code。
标签: c# unit-testing mstest