I've setup data driven unit tests in my solution. It's wired up, everything is working fine, which is what most of the articles and questions online seem to be focused around.
What I cannot find is how I read subsequent rows after the first row in any given column.
For example if my excel document is setup like so:
A | B
------ | ------
A1 | B1
A2 | B2
A3 |
A4 |
Then back in my unit test I do something like:
var getValue = TestContext.DataRow["A"];
var getOtherValue = TestContext.DataRow["B"];
The output is that getValue = "A1"
and getOtherValue = B1
. If I try to do something like this instead:
var getValue = TestContext.DataRow[0];
var getOtherValue = TestContext.DataRow[1];
The outputs are still exactly the same, which makes sense.
What I am confused with is how to get the value in A2
, A3
, B2
, and so on. That way I can test all of the different scenarios by just plugging them into excel.
For another example, if I have this table:
Cost | QtyOrdered
------ | ------------
10 | 10
5 | null
null | 2
null | null
In the above scenario I would like to run through all of the different rows and make sure that the values plugged in are what I expect. The first row I would expect 100
, and in every extra row I would expect an error message in my unit test.
I don't really see the point of data driven unit tests in excel if I can't just plug in a bunch of data in for multiple rows for each column.