EMF-IncQuery Testers' Guide
Testing framework overview
- org.eclipse.viatra2.emf.incquery.snapshot (+ .edit, .editor): For handling recorded match sets
- org.eclipse.viatra2.emf.incquery.testing.core: Xtend files for building test cases
- org.eclipse.viatra2.emf.incquery.testing.queries: EMF-IncQuery queries used by derived features in snapshot files and for comparing actual and expected snapshots
- org.eclipse.viatra2.emf.incquery.testing.ui: Query Explorer right-click menu contribution for Saving snapshots into .eiqsnapshots files.
- Used patterns can be parsed right from text (there are additional methods for loading a pattern model from file or uri as well)
- Input models are referenced from the recorded match set (there are additional methods for loading input models from file or uri as well)
- Recorded match sets are loaded from file or uri
-
Two comparing implementations:
- Use recorded match set as partial matches (reports unexpected and not found matches)
- Record actual match set and use EMF-IncQuery queries for listing unexpected and not found matches (this comparison method relies on correct behavior of matches on a limited feature set of the pattern language)
- Short-hand "assert" methods (see above) for the default behavior
- Additional methods can be suggested/implemented for other common use cases.
- Test cases can be run as JUnit Plugin Tests (this maybe changed if we register the matcher factory used by the derived feature in the match set record metamodel)
Important to know:
- EPackages must be registered at the time of the tests, so make sure to have correct dependencies set and include them into the runtime Eclipse.
- Patterns/input/record models must be accessible from the workspace, so they should be probably put in the same project as the test specification
Step-by-step guide for creating IncQuery Test Cases
-
You will need an EMF-IncQuery project, which contains an .eiq Query Definition file. Here you can find a working example project: https://github.com/ujhelyiz/EMF-IncQuery-Examples/tree/master/school/school.incquery
You can create an own EMF-IncQuery project here: File | New | Project | EMF-IncQuery | EMF-IncQuery Project.
-
You will need a plug-in project (!) which contains an instance model. If this project not a plug-in project, the jUnit Plug-in can’t load the instance model, so the test cases will not run.
In this example https://github.com/ujhelyiz/EMF-IncQuery-Examples/tree/master/school/school.instancemodel you can find two school instance models with a school, years, classes, students, teachers, and courses.
If you create a new plug-in project, you don’t need Activator (on the second wizard page, uncheck the „Generate an activator, a Java class that controls the plug-in’s life cycle”).
-
The test project is an other plug-in project. For an example test project with the correct settings and a representative set of test definitions, see: https://github.com/ujhelyiz/EMF-IncQuery-Examples/tree/master/school/school.tests
This project contains:
- school.tests/src/school/tests
The basic and model manipulation test cases in .xtend file
An example model manipulation test, where change the School "Budapest University of Technology and Economics" name to "BME":
- school.tests/model
Snapshot files
You can create an .eiqsnapshot file in Query Explorer: right click on a pattern result or the root of the patterns - Save EMF-IncQuery snapshot. Important: this file contains relative path to the instance model, so if you move this file to another folder, you need to check the path.
- school.tests/SchoolTests.launch
JUnit run configurations. You can run the tests: right click - run as - SchoolTests