Write Junit - eclipse-capella/capella GitHub Wiki
The plugin org.polarsys.capella.test.framework define basic test cases and tests suite.
Capella exisiting junits are currently written with JUnit3. Note that this will evolve at some point
- In MANIFEST/MANIFEST.MF file we need to depend on
org.polarsys.capella.test.framework
public abstract void test() throws Exception; //content of the test
public List<String> getRequiredTestModels(); //list of models to import before the test
protected List<BasicTestCase> getTests(); //list of tests to run
public List<String> getRequiredTestModels(); //OPTIONAL, list of models to import before the testsuite
When the model is defined at the test suite level, the test case are not allowed to modify the content of the model.
Test for the creation of elements in the Project Explorer: CreateElement.java
-
List of models to load getRequiredTestModels
-
Content of the test method test In this method, we use
getSession
to retrieve the opened session on the model. With aSession
we have access to theTransactionalEditingDomain
(allowing to execute commands) and then on theResourceSet
, the list of all loaded files.
By looking at how to Edit an element, it is possible to do some modification on the model (command to test) and then asserting that result is correct.
For instance, doing a Drag and Drop or Creating a REC/RPL ensuring that all references are created here
Diagram tests are more complicated to do, as it requires to open diagram, perform some manipulations and things like that.
- The plugin org.polarsys.capella.test.diagram.common.ju define some helpers.
In this plugin, many DiagramContext
defining all tools
org.polarsys.capella.test.diagram.common.ju.context, like Interface Diagram Blank
- In the context, we will be able to execute all existing tools, retrieve views, retrieve semantic elements.
In a Junit, a use of this diagram context, CreateInterface.java testing that the tool is enabled and create correct element in the right container. (All the asserts are done in super implementations, so the test is readable even if we think it does nothing).
Some other samples, CreateFunction.java or PABStyleChecksDiagramElements.java
- In MANIFEST/MANIFEST.MF file we need to depend on
org.polarsys.capella.test.diagram.common.ju