Sample module design (Example of Junit module)¶
In this section, a simplified example of real module development will be presented. The chosen subject is the development of a “JUnit Module” which provides facilities to build unit tests for a Java application model.
The Modelio JUnit Module builds a Java unit test model based on the user model following a simple paradigm: each class in the model that has to be JUnit-tested produces a corresponding JUnit test class.
The test model is then generated using the standard Modelio Java Developer Module, which also manages the compilation and execution of the Java code.
The features of this example JUnit Module are reduced to:
- Initial creation of the unit test model: the user selects a class in his model and activates the “Create a Test Case” command. The system creates a test class skeleton, in which all the operations of the selected class have an equivalent test method.
- Deletion of the unit test model when the tested model is removed: The user deletes a class from his model. The class had a link to a test case. The system automatically updates the test model by removing the corresponding test case.
In order to clearly identify the test case classes from the model and to be able to delete the test cases when the tested class is removed from the model, two stereotypes are defined :
- <<JUnit>> : put on created test case classes
- <<JunitDependency>> : put on the dependency created from the model class to its test case class.
The following figure give an example of a model class Motor and its test case class MotorTest created by our module.
Illustration 5: Example of model with JUnit test case