EasyTest : Loading Data using Excel

anujgandharv edited this page Nov 7, 2012 · 5 revisions

EasyTest provides its users with the facility to load the input test data using various file types. In this WIKI page we will see how a user can provide test data to its test classes using XML file.

In order to understand the concepts, lets take an example and walk through it:

 @DataLoader(filePaths={testData.xls} , loaderType=LoaderType.EXCEL)
 public class TestClass{
     public void simplTestMethod(@Param(name="name")String name , @Param(name="age")int age , @Param(name="expectedOutput")int expectedOutput){
       ...............//your test conditions here

As you can see, its a simple example of a TestClass that has a single method under test. The test method takes 3 parameters : name , age and expectedOutput.

We also see that we are using @DataLoader annotation on our class, which is a way to tell the EasyTest framework about how and from where to load the test data. DataDrivenTestRunner class from EasyTest understands how to load the test data and how to provide it to the test methods.

In our case, we are telling the EasyTest framework to load the input test data from a file path "testData.xls". EasyTest will try to search for this file in your relative path folder. Next, lets look at how we can define our testData.xls file.

Here is a sample XLS file that you can look at to see how we are defining the test data: https://github.com/EaseTech/easytest/blob/master/src/test/resources/testExcelData-update.xls This is how we define the input test data for the method defined above in the example:

                simplTestMethod	       name   	age    expectedOutput
                                          Ravi	32              1
                                    Christiaan	29              2
                                          Anuj	31              0

As you can visualize, we have in the first column, the name of the test method for which we need to define the test data. The name in this case is "simpleTestMethod". Next in the same column, we have defined the input parameter names that will be used in the test method. In this case the parameters are : name , age , expectedOutput. The next columns define the actual data associated with the test method and for each parameter. Thus, in the above case, the test method : simpleTestMethod will be executed 3 times with 3 sets of data defined in each column of the Excel file.

You can have as many test methods defined in a single file as you want. You can also use as many input files to load the data from as you want.

Very soon, and I mean really very soon, we will be supporting defining data in terms of Excel Objects. So a user can define a Date object as a value of the box in the given column and easyTest will take care of properly interpreting them and providing the right value to your test case.

I will keep you posted as and when that gets available.

Happy EasyTest(ing)