I have a DataTestMethod in my unit test using MSTest, and I have a string property in my constructor, let's say I have this code for example:
[DataTestMethod]
[DataRow("test")]
[DataRow(stringproperty)] // How is this?
public void TestMethod(string test) {
Assert.AreEqual("test", test);
}
Is it possible to pass a property as parameter in DataRow?
Thanks.
Yes if you use the 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" }
};
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With