Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 3ae6c9a48cce1d685a7ec498a276c92baaacb4e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
=Papyrus Testing Framework=

==Framework Goals==
* Automate the  development of test cases for Papyrus
* Set the bases for a model-based testing approach
* Ease the transition towards test-driven development

==User guide: How to generate tests for UML diagrams==
Currently, the framework supports the generation of unit tests for a diagram editor, taking as input an input .gmfgen.

===Testing diagram editors===
# Create tests plug-in, if it doesn't exist already. As a requirement, following the Papyrus development guidelines an Eclipse plug-in project must be created to contain the tests. Example: org.eclipse.papyrus.uml.diagram.component.tests.
# Add the dependency in the plug-in manifest towards the testing framework: org.eclipse.papyrus.tests.framework.
# Create the main Xtend transformation class for your diagram editor, detailing the name of the generated package of tests and the desired edit parts to test, as they are described in the gmfgen (See example below). 
# Create the generation launcher (either Xtend-based or Java-based) in an appropiate package, for instance org.eclipse.papyrus.uml.diagram.component.test.generation, in a file such as ComponentDiagramGenerateTestsWorkflow.xtend. Copy the example launcher below and replace with the values for the generation parameters for your own diagram editor. The parameters are:
#* testProjectName: the name of the test bundle project
#* gmfgenUri: URI for the input GMFGen file. The workflow object has a handy method to create a URI from a workspace path
#* testSrcGenLocation: Folder in the project where the launcher is located where the test code will be generated, for instance ''test-gen/''.  Do include the trailing slash for good measure
#* testModel: project-relative path of the UML-UTP intermediate model that will be generated. After launching the generation, this model provides an overview of all the generated test artifacts.  Do add this path to the git-ignore patterns
#* utpModuleFunction: an anonymous block that configures and returns a Guice module for the Xtend transformation (see the example below).  This module must be an instance of the GMFGen2UTPModule class that provides injection bindings for additional inputs (tweaks) to the transformation:
#** gmfgenMetamodel: the UML representation of the GMFGen metamodel, from the test framework (provided as a block argument). ''Required''
#** frameworkBase: the base test framework UML-UTP model (provided as a block argument). ''Required''
#** utp: the UTP profile from the UPR project (provided as a block argument). ''Required''
#** diagramTestPackageName: Java package name to contain the generated test suite. Tests are generated in sub-packages of this. ''Required''
#** diagramUpdater: name of the diagram updater class, if different from the GMFGen default (some diagram plug-ins customize it for some reason). ''Optional''
#** diagramCreationCommand: the name of the diagram creation command class, if different from the GMFGen default (some diagram plug-ins customize it for some reason). ''Optional''
#** testConstantsInterface: the name of the test constants interface, if different from the generation default (some diagram plug-ins customize it for some reason). ''Optional''
#** topContainerEditPart: simple class name of the diagram top container edit part in which to perform tests (often something representing a package or, for behaviour diagrams, a behaviour). ''Required''
#** topNodesToTest: array of simple class names of top node edit-parts to test. ''Required''
#** childNodesToTest: array of simple class names of child node edit-parts to test. ''Optional''
#** childLabelNodesToTest: array of simple class names of label node edit-parts to test. ''Optional''
#** linksToTest: array of simple class names of non-semantically-owned link edit-parts to test. ''Optional''
#** linksOwnedBySourceToTest: array of simple class names of semantically owned link edit-parts to test. ''Optional''
#** elementTypesAppearanceTests: array of element type IDs for which to generate appearance tests. ''Optional''
#** elementTypesDeleteTests: array of element type IDs for which to generate element deletion tests. ''Optional''
#** elementTypesDropTests: array of element type IDs for which to generate element drag-and-drop tests. ''Optional''
#** elementTypesEditTests: array of element type IDs for which to generate element editing tests. ''Optional''
# Launch the main method as a normal Java class.

The intermediate model and the JUnit code are generated.

===Example: Generation for the UML Component diagram===
Here is an example (ComponentDiagramGenerateTestsWorkflow.xtend):
<pre>
package org.eclipse.papyrus.uml.diagram.component.test.generation

import org.eclipse.emf.mwe2.runtime.workflow.WorkflowContextImpl
import org.eclipse.papyrus.tests.framework.mwe.GenerateTestsWorkflow
import org.eclipse.papyrus.tests.framework.gmfgenuml2utp.GMFGen2UTPModule

class ComponentDiagramGenerateTestsWorkflow {

	def static void main(String[] args) {
		val workflow = new GenerateTestsWorkflow()
		runWorkflow(workflow);
	}

	def static void runWorkflow(GenerateTestsWorkflow workflow) {
        workflow.testProjectName = 'org.eclipse.papyrus.uml.diagram.component.tests'
		workflow.gmfgenUri = workflow.resourceURI('/org.eclipse.papyrus.uml.diagram.component/model/ComponentDiagram.gmfgen')
		workflow.testSrcGenLocation = 'test-gen/'
		workflow.testModel = 'model/ComponentDiagramTest.uml'
		
        workflow.utpModuleFunction = [gmfgen, framework, utp |
            new GMFGen2UTPModule(gmfgen, framework, utp) => [
                diagramTestPackageName = 'org.eclipse.papyrus.uml.diagram.component.test'
                topContainerEditPart = 'PackageEditPart';
                topNodesToTest += #[
                    'PackageEditPart', 
                    'ModelEditPart', 
                    'ComponentEditPart', 
                    'InterfaceEditPart', 
                    'CommentEditPart', 
                    'ConstraintEditPart'
                ]
                childNodesToTest += #[
                    'ModelEditPartCN', 
                    'PackageEditPartCN',
                    'RectangleInterfaceEditPartCN', 
                    'ComponentEditPartCN', 
                    'ComponentEditPartPCN', 
                    'CommentEditPartPCN', 
                    'ConstraintEditPartPCN',
                    'InterfaceEditPartPCN'
                ]
                linksToTest += #[
                    'UsageEditPart',
                    'InterfaceRealizationEditPart',
                    'ManifestationEditPart',
                    'ComponentRealizationEditPart',
                    'AbstractionEditPart',
                    'DependencyEditPart'
                ]
                linksOwnedBySourceToTest += #[
                    'GeneralizationEditPart'
                ]
                
                elementTypesAppearanceTests += #[
                    'PackageEditPart', 
                    'ModelEditPart', 
                    'ComponentEditPart', 
                    'InterfaceEditPart', 
                    'CommentEditPart', 
                    'ConstraintEditPart'
                ]
                elementTypesDropTests += #[
                    'PackageEditPart', 
                    'ModelEditPart', 
                    'ComponentEditPart', 
                    'InterfaceEditPart', 
                    'CommentEditPart', 
                    'ConstraintEditPart'
                ]
            ]
        ]
        
		workflow.run(new WorkflowContextImpl);
	}

}
</pre>

==Generative Workflow==



==Framework Architecture==

The following class diagram shows the hierarchy of abstract classes extended by the generated test cases.

[[File:Papyrus_-_TestGenerationFrameworkBase.png| Hierarchy of abstract classes for the generated code]]

Currently, the test generation framework supports the following types of tests:

* Element creation from palette (nodes, nested nodes, links)
* Drag-and-drop
* Appearance tests
* Canonical synchronization

Back to the top