How do you get the iteration / line number from TestContext in data driven tests?

前端 未结 3 1161
一整个雨季
一整个雨季 2021-02-13 12:39

I\'ve implemented a data driven test using MsTest framework.

I was wondering if there was a way to get the iteration / line number of the current test code from the Test

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-02-13 13:28

    this is without the DataSource attribute but i can tell you that it iterate by it self without the for loop

         for (int i = 0; i < x; i++)
            {
                 int currentIteration = TestContext.DataRow.Table.Rows.IndexOf(TestContext.DataRow);
                 DataTable dt = TestContext.DataRow.Table;
                 int rowCount = dt.Rows.Count;
    
                 DataRow secondRow = dt.Rows[i];
                 string name = secondRow["name"].ToString();
                 int Balance = Convert.ToInt32(secondRow["Balance"]);
                 int Amount = Convert.ToInt32(secondRow["Amount"]);
                 int Count = Convert.ToInt32(secondRow["Count"]);
                 Assert.AreEqual(Balance, Amount);
    
            }
    

提交回复
热议问题