如何显式退出 MSTest 中的数据驱动测试方法
How to explicitly exit Data driven test method in MSTest
我使用 MS 测试框架中的数据驱动测试功能。 [DataSource] 属性指定 table。 C# 方法被标记为 [TestMethod]。它有效,但有时我需要停止执行。例如,table 有 100 行。如何在某些情况下明确地(过早地)退出测试方法(停止其余的 DDT 调用),比如在第 50 行调用此方法期间?
[DataSource("System.Data.SQLite", @"Data Source=D:\Test.db;", "TestTableName",
DataAccessMethod.Sequential)]
[TestMethod]
public void DataTest()
{
string userId = Convert.ToString(TestContext.DataRow["userid"]);
string telephone = Convert.ToString(TestContext.DataRow["telephone"]);
string email = Convert.ToString(TestContext.DataRow["email"]);
// .....
functionThatPerformsAssert(userId, telephone, email);
// .....
}
我从 functionThatPerformsAssert() 调用 Assert.Inconclusive 解决了这个问题,其中 _skipTest 确定是否跳过数据驱动测试中的当前行并开始下一行:
if (_skipTest)
Assert.Inconclusive("Test Skipped");
我使用 MS 测试框架中的数据驱动测试功能。 [DataSource] 属性指定 table。 C# 方法被标记为 [TestMethod]。它有效,但有时我需要停止执行。例如,table 有 100 行。如何在某些情况下明确地(过早地)退出测试方法(停止其余的 DDT 调用),比如在第 50 行调用此方法期间?
[DataSource("System.Data.SQLite", @"Data Source=D:\Test.db;", "TestTableName",
DataAccessMethod.Sequential)]
[TestMethod]
public void DataTest()
{
string userId = Convert.ToString(TestContext.DataRow["userid"]);
string telephone = Convert.ToString(TestContext.DataRow["telephone"]);
string email = Convert.ToString(TestContext.DataRow["email"]);
// .....
functionThatPerformsAssert(userId, telephone, email);
// .....
}
我从 functionThatPerformsAssert() 调用 Assert.Inconclusive 解决了这个问题,其中 _skipTest 确定是否跳过数据驱动测试中的当前行并开始下一行:
if (_skipTest)
Assert.Inconclusive("Test Skipped");