Skip to content
Permalink
Browse files

[TestGeneration] Adding top-level initialization for test class and f…

…ixing template structure . Also fixing generate targets for unit languages. making the default JUnit unless otherwise specificed.
  • Loading branch information...
SultanEid committed Oct 7, 2019
1 parent f8bc5e1 commit 44e3b43a0eecf300f855f0137007f3bf23235abc
@@ -6,6 +6,7 @@ use members_AllMethods.ump;
use members_AllTestCases.ump;
use members_Before.ump;
use members_After.ump;
use members_TestInit.ump;
use depends.ump;


@@ -76,15 +77,72 @@ class TestClassGenerator {

<<#
String coverageCriteria = "";
String unitLanguage = "";
for (GenerateTarget tr : model.getGenerates() )
{
if (tr.hasSuboptions())
{

//coverageCriteria = tr.getSubOption(0);
}
}


if (model.hasGenerates())
for (GenerateTarget gt : model.getGenerates())
{
if (gt.hasSuboptions())
{
for (String so : gt.getSuboptions()){

if( so.equals("JUnit"))
{
unitLanguage = "JUnit";
}

else if( so.equals("PhpUnit"))
{
unitLanguage = "PhpUnit";
}

else if( so.equals("RubyUnit"))
{
unitLanguage = "RubyUnit";
}

else
{
unitLanguage = "JUnit";
}
}

}

else {
if (gt.getLanguage().equals("Test"))
{
unitLanguage = "JUnit";
}
}

}

else { unitLanguage = "JUnit";}

#>>

<<=isAbstract>>Test <<=uClass.getName() >> {

generate <<=unitLanguage>> ;

<<@ UmpleToTest.depends >>

GIVEN:
<<=model.getUmpleFile().getFileName()>>;

<<@ UmpleToTest.members_TestInit >>

THEN:
<<@ UmpleToTest.members_Before >> <<@ UmpleToTest.members_AllAttributes >>
<<@ UmpleToTest.members_AllTestCases >>
<<@ UmpleToTest.members_AllMethods >>
@@ -0,0 +1,19 @@

class UmpleToTest {

members_TestInit <<!<</*members_TestInit*/>><<#

if (uClass.hasTestInits())
{
#>>WHERE:

<<#
for (TestInit ti : uClass.getTestInits()){
#>><<=ti.getCode()>>
<<#
}

}


#>>!>>}
@@ -303,8 +303,10 @@ class TestSequence {
class TestInit{
identifier;
objectName;
code;

0..1 -- * TestParameter;

}


@@ -687,10 +689,12 @@ class UmpleClass
//The possible Preconditions related to the Umple Class
1 -> 0..* Postcondition postConds;

//Umple Test Case at the cass level
//Umple Test Case at the class level
0..1 -- 0..* UmpleTestCase;
// class test sequence for testcases
0..1 -- 0..* TestSequence;
// class test initialization: inits at the top level
0..1 -- 0..* TestInit;

// The possible Constraints related to the Umple Class
1 uClass -> 0..* ConstraintTree;
@@ -320,6 +320,11 @@ class UmpleInternalParser
analyzeClassTestCase(token,aClass);
}

else if (token.is("testClassInit"))
{
analyzeTestClassInit(token,aClass);
}

else if (token.is("genericTestCase"))
{
analyzeClassGenericTestCase(token,aClass);
@@ -1082,6 +1082,16 @@ private void analyzeClassTestSequence(Token token, UmpleClass aClass) {
}
}

// test initializations at the class level, these are inits that were mesnt to be done at the global-level in the test class

private void analyzeTestClassInit(Token token, UmpleClass aClass) {
// TODO fix init code
TestInit ti = new TestInit("", "", "");
ti.setCode(token.getValue("code"));
aClass.addTestInit(ti);

}


// This method modifies the generic template to replace with the actual attribute name if it matches the type indicated in template
private String modifyGenericTestAttribute (Token token,UmpleClass aClass, Attribute att)
@@ -29,7 +29,7 @@ associationClassDefinition : associationClass [name] { [[associationClassContent
enumerationDefinition : enum [name] { [enumValue](, [enumValue])* }

// The following items can be found inside the body of classes or association classes
classContent- : [[comment]] | [[innerClass]] | [[mixsetDefinition]] | [[distributable]] | [[proxyPattern]] | [[classDefinition]] | [[trace]] | [[emitMethod]] | [[templateAttributeDefinition]] | [[primitiveDefinition]] | [[portDefinition]] | [[portBindingDefinition]] | [[position]] | [[displayColor]] | [[abstract]] | [[keyDefinition]] | [[softwarePattern]] | [[depend]] | [[symmetricReflexiveAssociation]] | [[attribute]] | [[testCase]] | [[genericTestCase]] | [[testSequence]] | [[stateMachine]] | [[activeMethodDefinition]] | [[inlineAssociation]] | [[concreteMethodDeclaration]] | [[constantDeclaration]] | [[modelConstraint]] | [[invariant]] | ; | [[enumerationDefinition]] | [[exception]] | [[extraCode]]
classContent- : [[comment]] | [[innerClass]] | [[mixsetDefinition]] | [[distributable]] | [[proxyPattern]] | [[classDefinition]] | [[trace]] | [[emitMethod]] | [[templateAttributeDefinition]] | [[primitiveDefinition]] | [[portDefinition]] | [[portBindingDefinition]] | [[position]] | [[displayColor]] | [[abstract]] | [[keyDefinition]] | [[softwarePattern]] | [[depend]] | [[symmetricReflexiveAssociation]] | [[attribute]] | [[testCase]] | [[genericTestCase]] | [[testSequence]] | [[testClassInit]] | [[stateMachine]] | [[activeMethodDefinition]] | [[inlineAssociation]] | [[concreteMethodDeclaration]] | [[constantDeclaration]] | [[modelConstraint]] | [[invariant]] | ; | [[enumerationDefinition]] | [[exception]] | [[extraCode]]
associationClassContent- : [[comment]] | [[classDefinition]] | [[position]] | [[displayColor]] | [[invariant]] | [[softwarePattern]] | [[depend]] | [[association]] | [[inlineAssociation]] | [[singleAssociationEnd]] | [[attribute]] | [[stateMachine]] | ; | [[extraCode]]
innerClass : [[innerStaticClass]] | [[innerNonStaticClass]]
innerStaticClass : static [[classDefinition]]
@@ -81,6 +81,11 @@ interfaceTest : test [~testName] ;
testSequence : testSequence [~sequenceName] { [[testSequenceEntry]] }
testSequenceEntry : [~name] ( -> [~name] )* ;

//top-level initialization

testClassInit : test Init { [**code] }


// Generic test case rules
genericTestCase : generic test [~testCaseName] OPEN_ROUND_BRACKET [[genericElement]] CLOSE_ROUND_BRACKET { ( [**code] )* }
genericElement- : [~elementType] [~genericElement] [[genericMethodParameters]]?
@@ -1,3 +1,5 @@
generate Test;


class Person {

@@ -32,6 +34,11 @@ class Person {
}


test Init {
Person p1 ("john" , 123);
}


garageDoor{

open{

0 comments on commit 44e3b43

Please sign in to comment.
You can’t perform that action at this time.