Test, Creating and Using Data Driven Tests - epam/Gepard GitHub Wiki
In this section we explain by examples what programmers should pay attention to when they're writing data-driven Gepard tests.
// Typical import declarations needed for a test
import com.epam.gepard.annotations.TestClass;
import com.epam.gepard.generic.GepardTestClass;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
@TestClass(id = "DEMO-2", name = "Data Driven Test Sample - CSV - Recommended DD approach")
public class DataDrivenSampleTestCSVTestParameterTest implements GepardTestClass {
private String tcRun = getDataDrivenTestParameter("ID");
private String tcText = getDataDrivenTestParameter("PART1");
private String tcAssertText = getDataDrivenTestParameter("PART2");
/**
* Sample test method, lists all the available data, and passes only if the 3. parameter is 'WILLFAIL'.
*
*/
public void testDoUseData() {
logStep("Test if we can use the params...");
logEvent("Param 1:" + tcRun + ", Param 2:" + tcText + ", Param 3:" + tcAssertText);
logStep("Test fails, if Param 3 is 'WILLFAIL'");
assertTrue("This need to be failed.", tcAssertText.compareTo("WILLFAIL") != 0);
}
}
Fine. But WHERE are the data for the test case?
1. The gepard.properties file specifies what is the data delimiter in case of txt data files, and where to find the data files. Right now the delimiter is '%' and the path was set to find the data files next to the java classes:
gepard.basefolder=.
gepard.datadriven.pathbase=${gepard.basefolder}/src/main/java
gepard.datadriven.columnsplitter=%
gepard.datadriven.feeder.class=LabelBasedDataFeeder
Do NOT change it.
2. Gepard will search for <classname>.csv file next to the classfile. If csv file is not found, tries to search for a <classname>.txt file.
This means you may use either TXT or CSV data files.
In the data file put one row for a Test Class run, and as many parameter in a row as necessary.
The sample file content below can be used to run the Test Case 4 times, and for every run 2 parameters are used.
Note: Do not forget, that the first parameter in each row is used to differentiate/name the test case in the logs.
##################################
# Tests for demonstration Purpose only....
##################################
index.hu%index.hu
portfolio.hu%www.portfolio.hu
alma%alma
korte%körte
Note on TXT files: Lines starting with '#' or '//' or if the line is empty, will be ignored.
Note on CSV files: The data separator is ','. No comment rows are used, and the first row is used to name the columns.
3. Finally, in the testlist.txt file, where the classes to be run are listed, put a number after the name of the class instructing Gepard to re-run the specific class many times (in our case, 11 times):
com.epam.gepard.examples.core.datadriven.DataDrivenSampleTestCSVTestParameterTest,11
That's all, now you can run data driven tests with Gepard.
Note: During TC development, it is suggested to set to run the TC only 1 time.
Q: What to do if I want to run the Nth test only?
A: In the data file, move the Nth data row to the top + set number of runs to 1 in testlist.txt
Q: Is that all about Gepard's data driven capabilities?
A: NOT. Data driven capabilities of Gepard is much more than specified here, so continue with figuring our what is the TestParameter annotation, and what are the Feeder classes, and what kind of further possibilities you have in testlist.txt.