Testing Graphiti Applications with Dark Feature Processing

Funded by the BMBF

Funded by the BMBF

Testing is as important for your Graphiti applications as it is for any other application. However, documentation is a little sparse for that topic. The posts on the Graphiti discussion forum will usually recommend one of two things: Have a look at the Unit tests in the Graphiti project and use SWTBot to test your applications.

For our application in the IMES project, we started with SWTBotTests, which work fine, but have two drawbacks:

  • It takes some effort to write them.
  • We have migrated our app to Eclipse Juno and SWTBot does not yet work well together with that release. So we’d have to wait until that is fixed.

 

So we started to look into the way that Unit testing in the Graphiti projects is done. The required objects are set up with the EasyMock framework. When following that path, we found that we’d need more things wired and less mock functionality than in the test projects and that it was not straightforward to set things up right.

However, Graphiti provides two features that are useful for testing: Executing commands programmatically and dark feature processing  (i.e. modifying the diagrams without an editor being actually open).

The setup of the test class is pretty simple. The exact logic of initializeTest() depends on how your domain model is connected to Graphiti’s Diagram model. In our case, we have two resources, one for the diagrams and one for the domain model and the diagram provider knows how to find the domain model for the diagram.

 

The execution of diagram commands / feature is done by EMF commands. So in the test cases, we have to create and execute these commands. An AbstractTestCommands holds common functionality for all the tests in the doExecute-Method and then delegates the testing to its concrete subclasses’ test methods.

 

As an example, we have one test case that make sure that port symbols cannot be directly places on a diagram (they can only be placed on certain other symbols). This test case looks like this.

 

All the tests run as plugin-tests in JUnit right now, because Graphiti queries several extensions during runtime.