Test, Data Feeders - epam/Gepard GitHub Wiki

Built-in Data Feeders

SimpleMultiplierDataFeeder

This feeder loads the data from the TXT and CSV data files, and use the first N rows. N is given as feeder parameter.

This is the most common usage of the feeders. Because of this, its parameter (int) can be used in the testlist file without specifying the feeder class, i.e. this is the default feeder for "int" type parameters.

Example 1, use SimpleMultiplierDataFeeder as default filer for integer parameters:

com.epam.gepard.examples.core.basic.SampleAfterBeforeTest,9

Example 2, use SimpleMultiplierDataFeeder as default filer for integer parameters:

com.epam.gepard.examples.core.datadriven.DataDrivenSampleTestCSV,SimpleMultiplierDataFeeder:11

SingleRowSelectorDataFeeder

Select the Nth row only, from an existing array. The First row is 1. This does not add new parameters, just reduces it to a single row, therefore parent feeder in the feeder chain is a must.

Example, select the 2rd row from the set of tests that contains 11 executions originally:

com.epam.gepard.examples.core.datadriven.DataDrivenSampleTest,SimpleMultiplierDataFeeder:11@SingleRowSelectorDataFeeder:2

BruteMultiplierDataFeeder

This feeder executes the input class several times, do nothing else. Be aware that ads " - #n" to the end of the first parameter, to identify the multiplication of the class.

Example, original test that was executed 11 times, was multiplied by 5 (resulting in 55 test class execution):

com.epam.gepard.examples.core.datadriven.DataDrivenSampleTestCSVB,SimpleMultiplierDataFeeder:11@BruteMultiplierDataFeeder:5

Label Based Data Feeder

This feeder is a complex feeder and has a bit different approach than the others has. Feeder parameter is has special format, starts with [ and ends with ]. Between these signs a feeder descriptor specified that can handle 4 sub-parameters, those are separated with : sign.

1. sub-parameter: Data file name It can be

  • an empty string or the string 'DEFAULT' - this will select the default test data for the test, same path as the test and same filename as the test itself
  • full path on the classpath separated by '/'-es, which describes the location of the data file
  • any other string, which is a key of a global (environment) property, eg.: feeders.example1=com/epam/feeders/ExampleFeerder.csv

2. sub-parameter: Row number to load All rows will be loaded if missing.

3. sub-parameter: Labels Only rows labeled with this string will be loaded. Labels relations can be AND (&) or OR (;) Examples:

  • All rows which have L1 or L2 labels: L1;L2
  • All rows which have L1 and L2 labels: L1&L2
  • All rows which have L1 and L2 labels or L3 and L4 labels: L1&L2;L3&L4

4. sub-parameter: Load type Values are: 'SEQUENTIAL', 'RANDOM', 'MERGE' where

  • SEQUENTIAL - loads feeder rows sequentially (default if missing)
  • RANDOM - loads feeder rows randomly
  • MERGE - loads all the feeder rows that are matching with the defined labels and merge them field by field using a comma separator. Can be useful in cases when simple values need to be combined and passed to a single test case.

Feeder relations Two or more feeders for a single test can be joined with a relational sign. Valid signs are: +, x Signs must be placed among feeders. A feeder will be associated with a sign on its left. The first feeder must not have a sign.

  • '+': joins one row from the right hand feeder sequentially (in RANDOM case rows are shuffled before join) with the next row from the left hand feeder
  • 'x': multiplies the rows in the left hand feeder then applies '+'.

Example for a complex LabelBasedDataFeeder usage (from gepard-examples module):

com.epam.gepard.examples.core.datadriven.LabelBasedDataFeederTest,:[]+[feeders.ONE:3:LABEL1]x[feeders.TWO:::RANDOM]

Data files: Prefer to use CSV data files, where:

  • The first row is the header.
  • Header's 1. column must be 'LABEL'
  • CSV must contain at least a LABEL and a value column.
  • You can insert an optional 'DESCRIPTION' column anywhere after 'LABEL'. Mixing multiple feeders will have a name generation mixing these columns.
  • Other header column names should reflect test parameter variable names from the test script. E.g. value of "userName" column can be accessed by calling getDataDrivenTestParameter("userName") method. Any other row can be commented with '//' or '#' on the beginning of the line. All other non commented rows are data rows. Cell values should be quoted ("value1") and separated with commas ("value1","value2").

FakeDataFeeder

This feeder just offers to give a single parameter value to the test class, no change in data array at all. If you use subsequent FakeDataFeeder, then you will get the latest parameter only. You can get the parameter value as String by using: String parameter = GenericListTestSuite.globalDataStorage.get("XFakeDataFeeder-" + className) call.

Writing your Own Data Feeders

The following interface need to be implemented: GepardDataFeeder See Javadoc of the interface class for details on how to implement the class.