我在使用 MSTest 的单元测试中有一个 DataTestMethod,并且在我的构造函数中有一个字符串属性,假设我有以下代码:
[DataTestMethod]
[DataRow("test")]
[DataRow(stringproperty)] // How is this?
public void TestMethod(string test) {
Assert.AreEqual("test", test);
}
是否可以在 DataRow 中将属性作为参数传递?
谢谢。
最佳答案
是的,如果你使用 DynamicDataAttribute
[DynamicData("TestMethodInput")]
[DataTestMethod]
public void TestMethod(string test)
{
Assert.AreEqual("test", test);
}
public static IEnumerable<object[]> TestMethodInput
{
get
{
return new[]
{
new object[] { stringproperty },
new object[] { "test" }
};
}
}
关于c# - 如何在 MSTest DataRow 中将属性作为参数传递,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47298140/