A data set contains data used by a test case and constraints.
A data set can have several variations.
Each variation has constraints that are called at the end of the test flow.
Example data set
Let’s see an example for CreateSimpleProductEntityTest. A data set and its corresponding test case must be placed in the <magento2_root_dir>/dev/tests/functional/tests/app/Magento/Catalog/Test/TestCase/Product directory.
The CreateSimpleProductEntityTest.xml data set contains:
This is a data set that:
corresponds to the XSD schema <magento2_root_dir>/dev/tests/functional/vendor/magento/mtf/etc/variations.xsd
relates to the Magento\Catalog\Test\TestCase\Product\CreateSimpleProductEntityTest test case (performs creation of the simple product)
relates to the ticket MAGETWO-23414 in Jira
contains variation CreateSimpleProductEntityTestVariation1 that
contains data to create product with fixed price (see descriptions in the following table)
defines tag that can be used to customize the test suite run
defines constraints that will be performed after the test flow in the order they are presented in the data set
The CreateSimpleProductEntityTestVariation1 variation contains the following $product data:
product/data/price/value is processed by a data sourceMagento\Catalog\Test\Fixture\Product\Price and is assigned 10000
product/data/price/dataset is assigned with a data set drop_down_with_one_option_fixed_price from the Magento\Catalog\Test\Repository\CatalogProductSimple\Price repository. This data set is used by a constraint.
field is assigned with Simple Product short_description %isolation%
field is assigned with Simple Product description %isolation%
field is assigned with 50
field is assigned with 657
field is processed by a data source Magento\Catalog\Test\Fixture\Product\CustomOptions using a data set drop_down_with_one_option_fixed_price from the repository Magento\Catalog\Test\Repository\Product\CustomOptions
fields are assigned with a data set simple_drop_down_with_one_option_fixed_price from the Magento\Catalog\Test\Repository\CatalogProductSimple\CheckoutData repository
Data set structure
A data set is an XML file that contains test variations for a test case.
Each variation includes:
Data used during the test flow and assertions
Constraints that are called after the test flow
The following table shows structure of the data set:
The root element that defines an XML namespace and an XML Schema.
Contains a reference to the test case class in attribute and variations in child elements.
name - full name of a test case class. Required.
summary - description of a test case. Required.
ticketId - identifier of related ticket. Optional.
Contains variation description in attributes and data with constraints in child elements.
name - a variation name. Required.
replace - a name of variation to be used instead of a variation indicated in name. Optional.
firstConstraint - a full name of constraint that is performed first. Optional.
method - a name of the test method from the test class. Optional.
summary - description of the variation. Optional.
ticketId - an identifier of the related ticket. Optional.
Data to be used by a test case.
name - a name of variable with extra data. More details. Required.
xsi:type - a type of the value.
The following data types are available:
Reference to the constraint class performed after the test flow.
name - a full name of the constraint class. Required.
next - a full name of the constraint class performing next in a queue. Optional.
prev - a full name of the constraint class performing previous in a queue. Optional.
A variation should contain only data that is required for its flow and constraints.
A data set should be placed in the same directory with a corresponding test case.
Data set merging
The FTF enables you to merge data sets from different modules. For example, if you create a new module that adds a menu option to an existing module, the FTF allows you to merge the new data with the existing data sets. As a result, you don’t have to edit the existing module to include the new information, and your tests continue to work. If you decide to later remove the same new module, you don’t need to clean the data sets in other modules.
There are two options to merge data sets in the FTF:
Also, in similar cases you can use array type in a data set, like:
Set a simple variable
For example, if a test case or constraint has an argument $price, then the test case takes from the data set all the <data> nodes with a name price. Assume a method with the $price argument.
To assign it with 10 in one of the variations, add the following field to a variation of the corresponding data set:
Set data to a fixture field
In your test you often need to use injectable fixture instances. For example:
In this case, the ObjectManager sends data to the InjectableFixture constructor. It declares that your data can be passed to the fixture in $data variable as an array. For example, to assign the existing fixture field weight with 50 you can use the following notation:
Set data to a fixture from a repository
The InjectableFixture class enables you to use a fixture repository. It can be injected in a $dataset variable. For example, to use dataset = product_with_special_symbols_in_name from the repository assigned in the fixture, you can use:
A CatalogProductSimple.xml fixture contains the following declarations:
The price fixture field contains the data source that assigns values from a repository. After the InjectableFixture class has passed data to the CatalogProductSimple fixture, Magento\Catalog\Test\Fixture\Product\Price data source receives ['dataset' => 'drop_down_with_one_option_fixed_price'] and assigns values from the ['dataset' => 'drop_down_with_one_option_fixed_price'] of the Magento\Catalog\Test\Repository\CatalogProductSimple\Price repository.
The checkout_data doesn’t contain source and is assigned with values from the Magento\Catalog\Test\Repository\CatalogProductSimple\CheckoutData directly.
Add a new variation
To add a new variation using merging, you should simply use the name of a test case that you want to merge with. For example, you want to add a new variations from the Magento_ProductVideo module to the Magento\Catalog\Test\TestCase\Product\UpdateSimpleProductEntityTest that is placed in the Magento_Catalog module. You can create data set in the Magento_ProductVideo module, containing variations you need, and paste the test case name that you want to merge with:
Create <magento2_root_dir>/dev/tests/functional/tests/app/Magento/ProductVideo/Test/TestCase/Product/UpdateSimpleProductEntityTest.xml with the following code:
Variations DeleteVideoFromPCFTestVariation1 and DeleteVideoFromPCFTestVariation2 will be used by the Magento\Catalog\Test\TestCase\Product\UpdateSimpleProductEntityTest class during the test run.
Extend a variation with data
If you want to extend variation in another module using merging, you should use a test case name that you want to merge with and a variation name that you want to extend.
For example, see how in Magento/Catalog/Test/TestCase/Product/ValidateOrderOfProductTypeTest.xml
the variation ValidateOrderOfProductTypeTestVariation1 is extended by the Magento_Bundle module:
Replace a variation
You can replace one variation with another using a replace attribute in the variation node. The replace attribute contains variation that must be replaced by a variation from a name attribute.
After a merge of a data set with the variation that is mentioned, a test will use CreateSuperNewCustomerBackendEntityTestVariation1 instead of CreateCustomerBackendEntityTestVariation1.