Skip to main content
Jump to: navigation, search

Difference between revisions of "Papyrus/Papyrus Developer Guide/Automatic Test Generation for Diagram Editors"

(Created page with "=Papyrus Testing Framework= == Framework Goals== * Automate the development of test cases for Papyrus * Set the bases for a model-based testing approach * Ease the transitio...")
 
Line 1: Line 1:
 
=Papyrus Testing Framework=
 
=Papyrus Testing Framework=
  
== Framework Goals==
+
==Framework Goals==
 
* Automate the  development of test cases for Papyrus
 
* Automate the  development of test cases for Papyrus
 
* Set the bases for a model-based testing approach
 
* Set the bases for a model-based testing approach
 
* Ease the transition towards test-driven development
 
* Ease the transition towards test-driven development
  
== How to generate tests for UML diagrams==
+
==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.
 
Currently, the framework supports the generation of unit tests for a diagram editor, taking as input an input .gmfgen.
  
==Testing diagram editors==  
+
===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.
 
# 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.
 
# Add the dependency in the plug-in manifest towards the testing framework: org.eclipse.papyrus.tests.framework.
Line 22: Line 22:
 
The intermediate model and the JUnit code are generated.
 
The intermediate model and the JUnit code are generated.
  
==Example: Generation for the UML Component diagram==
+
===Example: Generation for the UML Component diagram===
 
Here is an example (componentdiagramtest.qvto):
 
Here is an example (componentdiagramtest.qvto):
 
<pre>
 
<pre>
Line 78: Line 78:
 
class ComponentDiagramGenerateTestsWorkflow {
 
class ComponentDiagramGenerateTestsWorkflow {
  
 
 
def static void main(String[] args) {
 
def static void main(String[] args) {
 
val workflow = new GenerateTestsWorkflow()
 
val workflow = new GenerateTestsWorkflow()
Line 95: Line 94:
 
}
 
}
 
</pre>
 
</pre>
 +
 +
==Generative Workflow==
 +
 +
 +
 +
==Framework Architecture==
 +
 +
[[File:Papyrus_-_TestGenerationFrameworkBase.png| Hierarchy of abstract classes for the generated code]]

Revision as of 07:53, 3 November 2014

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

  1. 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.
  2. Add the dependency in the plug-in manifest towards the testing framework: org.eclipse.papyrus.tests.framework.
  3. Create the QVTO script 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).
  4. 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:
    • gmfgenUri: URI for the input GMFGen file
    • testSrcGenLocation: Folder in the project where the launcher is located where the test code will be generated, for instance test-gen.
    • qvtoScriptUri: URI for the QVTO script
    • testModelUri: URI where the UML-UTP intermediate model will be generated. After launching the generation, this model provides an overview of all the generated test artifacts.
  5. 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 (componentdiagramtest.qvto):

import canonicalTests;

modeltype UML uses uml('http://www.eclipse.org/uml2/5.0.0/UML');

transformation componentdiagramtest(in gmfgenUml : UML, in gmfgenMm : UML, in frameworkBase : UML, in utp : UML, out testModel : UML) extends canonicalTests(in gmfgenUml : UML, in gmfgenMm : UML, in frameworkBase : UML, in utp : UML, out testModel : UML);

main() {
	topContainerEditPart := "PackageEditPart";
	topNodesToTest := Set{
		"PackageEditPart", 
		"ModelEditPart", 
		"ComponentEditPart", 
		"InterfaceEditPart", 
		"CommentEditPart", 
		"ConstraintEditPart"
	} ;
	childNodesToTest := Set{
		"ModelEditPartCN", 
		"PackageEditPartCN",
		"RectangleInterfaceEditPartCN" 
		"ComponentEditPartCN", 
		"ComponentEditPartPCN", 
		"CommentEditPartPCN", 
		"ConstraintEditPartPCN",
		"InterfaceEditPartPCN"
	};
	linksToTest := Set{
		"UsageEditPart",
		"InterfaceRealizationEditPart",
		"ManifestationEditPart",
		"ComponentRealizationEditPart",
		"AbstractionEditPart",
		"DependencyEditPart"
	};
	linksOwnedBySourceToTest := Set{
		"GeneralizationEditPart"
	};
	gmfgenUml.rootObjects()[UML::Model]->map gmfgen2papyrusTest("org.eclipse.papyrus.uml.diagram.component.test");
}


Here is an example for the workflow launcher:

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

class ComponentDiagramGenerateTestsWorkflow {

	def static void main(String[] args) {
		val workflow = new GenerateTestsWorkflow()
		workflow.uriPrefix = "platform:/resource"
		runWorkflow(workflow);
	}

	def static void runWorkflow(GenerateTestsWorkflow workflow) {
		workflow.gmfgenUri = workflow.uriPrefix + '/org.eclipse.papyrus.uml.diagram.component/model/ComponentDiagram.gmfgen'
		workflow.testSrcGenLocation = 'test-gen-15072014'
		workflow.qvtoScriptUri = workflow.uriPrefix + '/org.eclipse.papyrus.uml.diagram.component.tests/qvto/componentdiagramtest.qvto'
		workflow.testModelUri = workflow.uriPrefix + '/org.eclipse.papyrus.uml.diagram.component.tests/model/ComponentDiagramTest.uml'
		workflow.run(new WorkflowContextImpl());
	}

}

Generative Workflow

Framework Architecture

Hierarchy of abstract classes for the generated code

Back to the top