Texo/Test Data Generation
Texo Test Data generation operates on Ecore and XSD models and generates EObjects. This means that there is no dependency on Texo, the test data generation can be used in any project working with EMF.
To make use of Test Data Generation you have to install the Texo Data Generator feature.
Features and Limitations
The main features:
- takes into account containment and bidirectional relations, so EObjects are always created in a containment hierarchy.
- to set ereferences it tries to re-use already created EObjects (of the correct type), to not generate too many objects
- can handle EReferences to abstract types/interfaces (to set such an ereference will randomly select concrete subtypes)
- created EObjects are added to containers if they are present, if there is more than one possible container then it will select one randomly.
- the test data generator uses data generators for specific eattributes. These eattribute data generators are pretty simple to implement and add
- There are data generators for the numeric types, enum, date and string.
- For String data generators there are some specific implementations for firstname, lastname, city, street, zipcode, postal code, phone. All of these use a name/word list to generate readable data. So if you have an eattribute with the name firstname it will use a specific datagenerator which uses readable names. Overall the idea is to extend this with more name/word list if there is interest.
The main limitation is that the data generator ignores most constraints (if you have defined any like using OCL), this is a future topic.
The usage is probably best described with a code snippet:
final ModelDataGenerator modelDataGenerator = new ModelDataGenerator(); modelDataGenerator.setStartEClasses(eClasses); modelDataGenerator.setMaxDepth(maxDepth); modelDataGenerator.setCollectionSize(collectionSize); modelDataGenerator.setDataSize(dataSize); modelDataGenerator.setMaxObjects(maxObjects); modelDataGenerator.setEPackages(ePackages); modelDataGenerator.generateTestData(); System.err.println("Generated " + modelDataGenerator.getTotalObjectCount() + " objects "); List<EObject> result = modelDataGenerator.getResult();
To explain the different parameter settings in more detail:
- startEClasses: the data generator will start by creating instances of these EClasses, so these are considered to be the top-instances returned also in the result.
- maxDepth: counting from the start of the graph this is the max depth in the association path counting from the top instance created. The system will create EObjects to set EReferences, if the maxDepth has been reached then this is only done for required EReferences and not for optional ones.
- dataSize: the number of instances created for each EClass set as a start EClass.
- maxObjects: the system will try to stop creating objects after this number of objects has been created. Meaning, that when this number is reached only mandatory EReferences are filled.
- maxObjectLimit: is set equal to 2*maxObjects, but can be set explicitly also. The system will not create more then this number of objects and always stop when it is reached.
- ePackages: the ePackages for which test data is created. Is set separately because the start EClasses may not be related to all EPackages which need to be considered when creating testdata.
More documentation can be found in the java doc of the ModelDataGenerator class.