N
Nadim2522
Guest
I have a DynamicData test which is based on: https://www.meziantou.net/mstest-v2-data-tests.htm#using-dynamicdata
In my own case, I have a Pre Test (TestInitialize) and Post-Test (TestCleanup), and I need to get the dynamic data value from that pre-test and post-test. I mean, I need to get the the value of the arguments "a", "b" and "expected" from both TestInitialize and TestCleanup methods.
Here is a sample code:
[DataTestMethod]
[DynamicData(nameof(GetData), DynamicDataSourceType.Method)]
public void Test_Add_DynamicData_Method(int a, int b, int expected)
{
var actual = MathHelper.Add(a, b);
Assert.AreEqual(expected, actual);
}
public static IEnumerable<object[]> GetData()
{
yield return new object[] { 1, 1, 2 };
yield return new object[] { 12, 30, 42 };
yield return new object[] { 14, 1, 15 };
}
[TestInitialize]
public virtual void PreTest()
{
}
[TestCleanup]
public virtual void PostTest()
{
}
Can you please assist?
Best Regards,
Nadeem Bader
Continue reading...
In my own case, I have a Pre Test (TestInitialize) and Post-Test (TestCleanup), and I need to get the dynamic data value from that pre-test and post-test. I mean, I need to get the the value of the arguments "a", "b" and "expected" from both TestInitialize and TestCleanup methods.
Here is a sample code:
[DataTestMethod]
[DynamicData(nameof(GetData), DynamicDataSourceType.Method)]
public void Test_Add_DynamicData_Method(int a, int b, int expected)
{
var actual = MathHelper.Add(a, b);
Assert.AreEqual(expected, actual);
}
public static IEnumerable<object[]> GetData()
{
yield return new object[] { 1, 1, 2 };
yield return new object[] { 12, 30, 42 };
yield return new object[] { 14, 1, 15 };
}
[TestInitialize]
public virtual void PreTest()
{
}
[TestCleanup]
public virtual void PostTest()
{
}
Can you please assist?
Best Regards,
Nadeem Bader
Continue reading...