Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

VIATRA/Query/DeveloperDocumentation/FeatureSetAndTesting/Testingframework

Testing framework

With Testing Framework, you can define EMF instance models from your query results. You can also modify these models.

Creating snaphot (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.)

Savesnapshot.png

You can create your own new .eiqsnapshot or you can add it to an existing one.


New .eiqsnapshot:

  • a new EMF instance model is created
Newsnapshot.png


Existing .eiqsnaphot:

  • at this time, the query match result will be added to an existing result
Existingsnapshot.png



EIQ Snapshot Editor

You can modify your .eiqsnapshotmodel here:

  • Create new child
  • Create new sibling
  • Validate
  • Load resource
  • Refresh (model)
  • Show properties view (more information, depends on context)
    • pattern qualified name
    • role
    • derived value
    • parameter name
    • value


Snapshoteditor.png


Testing framework overview

Test cases can be defined using the following way (if the test is to check that the match set of queries is equal to the recorded match set):

https://gist.github.com/abelhegedus/2949020#file-test-java

For an example test project with the correct settings and a representative set of test definitions, see: [1]

  • 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

1. You will need an EMF-IncQuery project, which contains an .eiq Query Definition file. Here you can find a working example project: [2] You can create an own EMF-IncQuery project here: File | New | Project | EMF-IncQuery | EMF-IncQuery Project.

2. 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 [3] 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”).

3. 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: [4]

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":

https://gist.github.com/ujhelyiz/3722668

  • 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

See also http://incquery.net/node/124

Back to the top