EMFT Texo: model-driven test data generation
When doing test driven development often/most of the time specific test data is created to test a specific situation. This makes sense as with specific test data you can test very specific functions of your code. However, creating test data is a tedious job and there is never enough time to do it all.
For Texo I wanted something different: model-driven testing, which starts with generating test data on the basis of an ecore/xsd model. With model-driven testing I only need to add a model to the test framework and the rest is taken care of: code and orm/jpa generation, test data generation, persisting, converting, comparing of results etc.
To support the Texo test framework Texo includes a test data generator: which generates EMF EObjects (with data and references) on the basis of an ecore model. The EMF EObjects can be used in other EMF tools such as EMF compare for comparing results. In Texo the EMF objects are converted to real java pojos and persisted in the database or serialized as xml/xmi.
Now, let’s see some code, how can you actually generate test data:
<pre>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();</pre>
You define the eclasses you want to have in the top of the containment hierarchy (startEClasses) and a set of parameters which define the depth and breadth of the generation. The result is a list of EObjects which form the root of the containment hierarchy.
Texo test data generation tries to be smart when generating test data:
- required efeatures are always set
- objects which are created are re-used in references from other objects
- for filling primitive values specific (overridable) value generators are used
This wraps it up, Texo provides test data generation and uses it for a model-driven test environment. Model-driven testing is a great addition to traditional specific testing. Model-driven testing has an attractive ‘mass’ side to it, it makes it very easy to add new models to the test environment thereby increasing the test coverage.