Reputation: 2673
need advice on data driven test automation.
I am doing test automation using C# ann Nunits for a web application which is developed using MVC. We are using Selenium web drivers for this.
As part of data driven testing, which one is good to use for input test data is it xml files or a sql server db.
If we are using db is it good to have some ORM(NHibernate) for db connectivity.
Thanks
Upvotes: 2
Views: 4755
Reputation: 291
Consider storing you test data in embedded json files instead of excel or a database.
Storing in json will have the following benefits.
This provides good support for managing your test data in embedded json files
Upvotes: 0
Reputation: 30698
data-driven-test-in-nunit-with-csv
How to use
[Test, TestCaseSource("GetTestData")]
public void MyExample_Test(int data1, int data2, int expectedOutput)
{
var methodOutput = MethodUnderTest(data2, data1);
Assert.AreEqual(expectedOutput, methodOutput, string.Format("Method failed for data1: {0}, data2: {1}", data1, data2));
}
private IEnumerable<int[]> GetTestData()
{
while (data.ReadNext()) // Use your custom logic based on Stream to get new data (basically Implement IEnumerator on data class)
yield return new[] { data.Current };
}
Other testing frameworks
MS Test
XUnit
Upvotes: 4
Reputation: 37566
Consider using Mockobjects to simulate the data, try these links:
Upvotes: 0
Reputation: 217
My suggestion would be to bundle the test data into the unit test fixture itself. The setup of each test method would set up the initial state (data) for the test; and the teardown would clean it up (if necessary).
Trying to maintain an external data file and keep it consistent with the unit test code is asking for trouble. (YMMV - this is my advice from personal experience.)
Upvotes: 0
Reputation: 25056
See whichever fit your bill.
If you've got a good ORM, and you are comfortable with it, use it.
If you are more comfortable with XML - do it.
Think about long running times when it becomes an issue. You are not writing unit tests with Selenium, you are writing integration UI tests. Therefore they are generally run at night anyway, so long running times rarely become an issue.
Personally, here, we use LINQ2SQL and for any data I hop over to the SQL server DB and it works fine - providing your queries are not silly, there is little performance hit.
Upvotes: 0