Question

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

Was it helpful?

Solution

data-driven-test-in-nunit-with-csv

Parameterized Tests in NUnit

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

OTHER TIPS

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.

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

Consider storing you test data in embedded json files instead of excel or a database.

Storing in json will have the following benefits.

  1. No impedence in test code due to schema
  2. No connectivity problems
  3. The test data will be available as a part of your project

This provides good support for managing your test data in embedded json files

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top