TDD - Supplying a set of rows to a single Test multiple times

J

Jay Pondy

I need to run a single test multiple times based on SETS of rows from an
Excel spreadsheet - not just one row at a time.

I have looked at the "data driven" test example for adding two numbers and
verifying the result. The problem is that this example applies the test to
only ONE row at a time and I need to apply a single test multiple times using
a varying set of rows during each run.

As far as I can tell a TestMethod is run only once with the exception of the
"data driven" type where the method is decorated with the DataSource
attribute. I need the method run and the results of each run reported
multiple times.

I tried looping in a test method but as soon as the first test fails the
method is aborted and the result reported.

Any guidance would be most appreciated as I am fairly new to the Visual
Studio testing environment.


Jay Pondy
 
M

Mr. Arnold

Jay said:
I need to run a single test multiple times based on SETS of rows from an
Excel spreadsheet - not just one row at a time.

I have looked at the "data driven" test example for adding two numbers and
verifying the result. The problem is that this example applies the test to
only ONE row at a time and I need to apply a single test multiple times using
a varying set of rows during each run.

As far as I can tell a TestMethod is run only once with the exception of the
"data driven" type where the method is decorated with the DataSource
attribute. I need the method run and the results of each run reported
multiple times.

I tried looping in a test method but as soon as the first test fails the
method is aborted and the result reported.

Any guidance would be most appreciated as I am fairly new to the Visual
Studio testing environment.


Jay Pondy

You need a testing method where the TestClass can run multiple test
methods independent of each other. One test fails, it's reported and the
other tests continue.

Each row you're talking about is an independent test method within the
TestClass, and you run all tests at the class level meaning run them all.
 
J

Jay Pondy

Mr. Arnold

Can you clarify what your saying in a bit more detail as I am not sure
exactly what you mean.

In pseudo code what I need is:

foreach scenario in scenarios
select testrows where scenario = scenario
LoadObject being tested with the test rows
Assert(ExpectedRows, ActualRows, "Failed")

The object under test needs to apply an Absentee Policy and "should" only
return those rows that are flagged in the set it was given to examine.

What I have cobbled together so far is:

[TestMethod]
[DataSource("System.Data.OleDb", @"Provider=Microsoft.Jet.OLEDB.4.0; Data
Source=Absentee Policy Tests.xls; Persist Security Info=False; Extended
Properties='Excel 8.0;HDR=Yes;'", "Scenarios$", DataAccessMethod.Sequential)]
[DeploymentItem("Absentee Policy Tests.xls")]
public void TestAbsenteePolicyScenarios()
{
// Grab the next Test Scenario from Excel via the TestContext DataSource
int scenario = Convert.ToInt32(TestContext.DataRow["Scenario"]);
string title = (string)TestContext.DataRow["Title"];

// Fetch the Test Rows for this scenario
string testsQuery = string.Format("select * from [Tests$] where scenario
= {0}", scenario.ToString());

OleDbDataAdapter adp = new OleDbDataAdapter(testsQuery,
(OleDbConnection)TestContext.DataConnection);
DataTable tbl = new DataTable();
adp.Fill(tbl);

// Construct the object to be tested
EmployeeIncidents source = IncidentsFactory(tbl);
EmployeeIncidents expected = ExpectedIncidentsFactory(tbl);

// Assertion code for collection testing not implemented yet
}


My Excel spreadsheet contains two tables:

Scenarios
ID Title

Tests
Scenario ColumnTestData... IncludeInExpected


The only reason I have the Scenarios table is to leverage the TestContext
DataSource. As it reads each scenario row I use the ID value to filter the
tests ie; for scenario ID 1 I only need the tests with that ID.

It would be nice to just have the "Tests" table in Excel and then do a
select distinct on the Scenario column but I don't quite see how to
manipulate the datasource in the TestContext to reach this goal.

Anyway I'm not quite sure what you're saying with you suggestion.
 
M

Mr. Arnold

Jay Pondy wrote:

<snipped>

I not saying you should change, but I think MBUnit is a lot more simpler
to use and run test, which is part of the .Net Framework

I suspect that you can hit a datasource doing Row Testing.

http://haacked.com/archive/2007/06/14/easily-test-your-code-for-multiple-cultures.aspx


And maybe, you figure out how to run multiple tests under one
[TextFixture]. I am sure the test framework you're using can do
something similar.

You need to use Bing or Google and look up how to do things, as others
have gone down the path and provided information on how to do it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top