MSTest - 是否可以在 TestInitialize 和 TestCleanup 中访问 [DataRow] 值?



我有这样的测试:

[DataTestMethod]
[DataRow("example1")]
[DataRow("example2")]
public void Test_Example(string name)
{
// test logic
}

我们的日志记录系统目前在基础[TestClass]中以单一[TestCleanup]方法实现。

我可以通过TestContext属性访问测试方法的名称,但这不包括有关数据行参数的任何信息。

是否有可能以某种方式获得这些值?在[TestCleanup][TestInitialize]会做得很好。

您是否查看过 TestContext 对象上的 DataRow 属性?这可能就是你所追求的。

https://learn.microsoft.com/en-us/dotnet/api/microsoft.visualstudio.testtools.unittesting.testcontext.datarow?view=mstest-net-1.2.0

最新更新