Skip to main content
Jump to: navigation, search

Texo/Test Data Generation

< Texo
Revision as of 13:16, 31 January 2010 by (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


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. It is possible to add or create your own data generators. Some examples of the ones delivered with Texo:
    • 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();
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.

Using custom/additional data generators

There are for sure cases that it makes sense to create your own data generators. This can be accomplished quite easily:

  • implement the data generator you want to use, for example by extending one of the existing data generators: EClassDataGenerator, EReferenceDataGenerator, EAttributeDataGenerator (and its subclasses in the org.eclise.emf.texo.datagenerator.attributegenerators package.
  • extend the DataGeneratorFactory or implement your own which creates the custom data generator for the EStructuralFeature/EClass you are targeting.
  • After creating a ModelDataGenerator set your own DataGeneratorFactory in this ModelDataGenerator (call setDataGeneratorFactory(..)).
  • When generating data your custom data generator will be used.

Back to the top