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

牧云@^-^@ 提交于 2019-12-03 11:07:23

Try this:

int currentIteration = TestContext.DataRow.Table.Rows.IndexOf(TestContext.DataRow);
private readonly PropertyInfo _rowIdProp = typeof(System.Data.DataRow).GetProperty("rowID", BindingFlags.NonPublic | BindingFlags.GetProperty | BindingFlags.Instance);

..

// No datarow means only one iteraton

var currentIteration = DataRow == null ? 1 : (Int64)_rowIdProp.GetValue(DataRow, null);

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);

        }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!