Data driven Testing is a sequence of test steps are automated to run repeatedly for different set of data to verify the expected results.
The data-driven test in the Nunit framework is achieved through the TestCase attribute and TestCaseSource attribute.
The parameter can be passed to the TestCase attribute, if the method is marked as TestCase it consider as Test
[TestCase("John","will")]
[TestCase("Alex", "bill")]
[TestCase("Mat", "stokes")]
public void LoginTest(int firstname, int lastname)
{
Console.WriteLine("Firstname- " + firstname+ "Lastname is - "+lastname);
}
In the above example, three times the parameter is passed through TestCase attribute the LoginTest will run three times with three different parameters.
Output:
To pass dynamic data to the test, the data can be from an external file system like CSV, EXCEL or Database then TestCase source is the nice option.
The TestCaseSource attribute takes the name of a static property which will provide the input data,
There are many ways to work with TestCaseSource attribute, one method is using TestDataClass,
For example, we can pass the credentials from CSV and pass it to the TestCaseSource