Getting started using DDSteps
The purpose of this example is to visualize how to use Excel together with DDSteps and how to get started using DDSteps.
If you're in a hurry then instead:
- check out the code in the package "org.ddsteps.samples.firstdatadriven" which is in the module "ddsteps/samples-basic" in CVS.
or better still
- view the video
showing a string comparator example.
Creating a Test Class
Creating a Test Class
1. Create a class FirstDataDrivenTest that extends org.ddsteps.DdTestCase and implement the abstract method protected DataLoader createDataLoader().
2. Add the following Fields (member variable) to FirstDataDrivenTest.java
private String someText;
private int someNumber;
private boolean someBoolean;
Create access methods (getters/setters) for the three members according to JavaBeans specification.
3. Create method public void testFoo() throws Exception and implement the following code:
public void testFoo() throws Exception {
assertTrue("Fail on someNumber = 11.", someNumber != 11);
assertTrue("SomeBoolean cannot be false.", someBoolean);
}
4. Now we need to read our Excel file which will contain our test data. To read this data the method createDataLoader() needs the code:
protected DataLoader createDataLoader() {
return CachingExcelDataLoader.getInstance();
}
Creating the Excel file
Creating the Excel file that hold your test data.
1. Create an Excel file, which must have the same name as the Java class: "FirstDataDrivenTest.xls". Put it in the same directory as the FirstDataDrivenTest.java file, right in with yoru source. If you want to, you can use the Excel template, template.xlt, that is in the resources folder in the distribution.
2. Rename Sheet1 to "testFoo" (same as your test method).
3. A good practice is to write the name of the test method on the first row of the Excel sheet as a header.
4. Then we need to insert which fields in the Excel file corresponds to which field(member variable) in the test class. This is done by inserting a row in the sheet with — and then as good practice a comment Header starts here.
5. Then for each field(member variable) insert the field name in a column under the row created in step 8 . For FirstDataDrivenTest in column A insert text, in column B insert number and in column C insert someBoolean.
6. Now the specific test data is about to be inserted, but first insert a new row as in step 8. The first cell contains — and then another cell should contain data starts here as a comment.
7. Insert the test data in column A, the column which contains test and the data belonging to the test field:
Under column B insert test data to field number.
Under column C insert test data to field someNumber.
8. Finally the Excel sheet must mark the end of test data which is done in the same manner as step8 and 10. Insert a new row with "---" and add a in another cell the comment "Data ends here".

Figure: Here's an example Excel file.
Running the example
In this chapter we try to run the example in Eclipse as an ordinary JUnit test.
1. Run
Right-click the "FirstDataDrivenTest.java" file and select "Run as" and "JUnit Test".

Figure: Running the example in Eclipse. Note that the errors are on row 11 and 12 are there by intention.
2. Fix
Once you've had a look around to see the different output information, try fixing row 12 in the Excel-file.
Right-click the Excel-file (in Eclipse), select "Open With" and then "System Editor".
Change cell C12 to TRUE and save.
3. Run just the single row
Go back into Eclipse (the Package Explorer).
Refresh (F5) the "FirstDataDrivenTest.xls" file!
Go to the JUnit output view and run just that row (12) by right-clicking on it and selecting "Run".
Since we rerun just row 12, we should now get at green bar.
If you run all of the rows, then the error output should only consist of row 11.
The class DDStepsTestCase is deprecated so I used DDStepsTestCase. Is this correct?
The static method CachingExcelDataLoader.getInstance() is also deprecated. I used DataLoaderFactory.getCachingExcelDataLoader(). Is that correct?