Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

EasyTest : Loading Data using XML

Anuj Kumar edited this page · 4 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.xml} , loaderType=LoaderType.XML)
 public class TestClass{

     public void simplTestMethod(@Param(name="name")String name , @Param(name="age")int age , @Param(name="expectedOutputs")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.xml". EasyTest will try to search for this file in your relative path folder. Next, lets look at how we can define our testData.xml file.

The XML structure that EasyTest supports is defined in the following Schema Definition file:

So, lets see how our testData.XML file will look like for the example test method above and then we will try to understand it piece by piece:

       <?xml version="1.0"?>

      <easytest:InputTestData xmlns:easytest="urn:org:easetech:easytest:1.0"
       xsi:schemaLocation="urn:org:easetech:easytest:1.0 testDataSchema.xsd">

        <TestMethod name="simplTestMethod">
          <Description>Description for this test input instance
          <TestRecord id="1">
          <Description>Description for this test input instance
             <Entry key="name" value="Daniel" />
             <Entry key="age" value="25" />
             <Entry key="expectedOutputs" value="2" />
           <TestRecord id="2">
           <Description>This test tries to capture the scenario when the data is
                 available in the DB
               for the given set of input parameters. In this
               case the expectedItems
               should be 1.
           <Entry key="name" value="kumar" />
             <Entry key="age" value="32" />
             <Entry key="expectedOutputs" value="1" />
         <TestRecord id="3">
         <Description>This test tries to capture the scenario when the data is
           available in the DB
           for the given set of input parameters. In this
           case the expectedItems
          should be 0.
             <Entry key="name" value="christy" />
             <Entry key="age" value="28" />
             <Entry key="expectedOutputs" value="0" />


So lets try to dissect the above XML file: The first 4 lines define the easytest namespace and the root element: "InputTestData". Nothing special. Next, we have the tag : TestMethod which has a single attribute: name.

TestMethod Tag

The "name" attribute has the name of the test method(as value) for which the test data is defined. Thus in our case the name attribute will have the value : "simplTestMethod".

TestMethod tag has the following child tags:

  • Description : which provides the description about the method under test(Optional)
  • TestRecord : which identifies a SINGLE input data set for a given test method. Thus if we have 3 TestRecord tags under a given TestMethod tag, EasyTest framework will run the test method 3 times, each time providing the inputs to the test method from the TestRecord tag. We will look at the TestRecord Tag in more detail below.

TestRecord Tag

The TestRecord tag under the TestMethod tag identifies a single instance of test input for the given test method. It has the following child attribute:

  • id : This is a record Id that is for convenience to the EasyTest Framework to support its output functionality. In case you are not writing output back to the file, this value does not have any significance and can be any value. In case you want the EasyTest framework to capture the output, you should take care of the condition that this value should be unique in the given file. Thus no two test record should have the same "id" value. If they do then the behavior of EasyTest framework is undefined.

The TestRecord Tag has the following chile tags:

  • Description : the description of the given test record instance(foir eg. specifying that the given record tests the boundry condition)
  • InputData tag that containsthe input data
  • OutputData tag that is never used by the end user. Instead it is reserved for the EasyTest framework to write data back to the file.

Input Data tag further has the following child element:

  • Entry : This tag actually defines the input data for a single input parameter of the test method. Thus if you have a method that takes three input parameters, then you will have 3 entry tags inside the InputData tag, one for each input parameter.

Entry tag has two attributes:

  • key : that defines the name of the input parameter(normally provided as part of the @Param annotation on the test method parameters)
  • value : the value associated with the input parameter.

EasyTest framework will take care of converting the String values to proper values(like int , long , or even your custom objects , using PropertyEditor support or Converter support).

In case you have more questions or doubts regarding the XML functionality or any other functionality, you can either drop a mail to or open an issue directly on the easytest github page.

Enjoy EasyTest(ing).

Something went wrong with that request. Please try again.