SDA SE Wiki

Software Engineering for Smart Data Analytics & Smart Data Analytics for Software Engineering

User Tools

Site Tools


Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
research:jtransformer:tutorial:testing [2014/11/27 15:31]
127.0.0.1 external edit
research:jtransformer:tutorial:testing [2018/05/09 01:59] (current)
Line 1: Line 1:
 +====== Testing ======
  
 +When writing analyses or transformations you often want to test 
 +  * that a particular piece of source code results in a particular set of facts, or 
 +  * that a factbase has a particular structure after a transformation.
 +
 +For instance, assume you want to make sure that the source code
 +
 +<Code lang-java>​
 +   class HelloWorld { 
 +     ​String message; ​
 +   }
 +</​Code>​
 +
 +is actually translated to the following PEFs
 +
 +<Code lang-prolog>​
 +   ​classT(28446,​ 28445, '​HelloWorld',​ [], [28447, 28453]).
 +   ​fieldT(28453,​ 28446, 10005, message, null).
 +</​Code>​
 +
 +However, you cannot know the exact element IDs. You only want to express that 
 +  * the the inter-PEF links expressed by the IDs and  ​
 +  * the constants in the PEFs 
 +are as you expect. You can do this by keeping the constants but replacing the 
 +each concrete ID consistently by the same logic variable. Then the test condition ​
 +that you want to express can be written as a predicate:
 +
 +<Code lang-prolog>​
 +  test(myTest) :- 
 + packageT(Package,''​),​
 + compilationUnitT(CompilationUnit,​Package,​_FileS,​[],​[Class]),​
 + classT(Class,​CompilationUnit,'​HelloWorld',​[],​[_SynteticConstructor,​Field]),​
 + fieldT(Field,​Class,​StringType,​message,​null),​
 + fully_qualified_name(StringType,​ '​java.lang.String'​ ). 
 +</​Code>​
 +
 +This predicate would suceed on any factbase that has the proper structure, including
 +the proper constants in the proper places. If anything is other than expected, the predicate ​
 +will fail. 
 +
 +Unfortunately,​ we would not know why the predicate failed, that is, which of the individual ​
 +conditions caused the test to fail. In order to get this information,​ we can wrap each 
 +condition in a call of the assertion/1 predicate, which will throw an exception and output ​
 +a specific message if the wraped condition failed:
 +
 +<Code lang-prolog>​
 +  test(myTest) :- 
 + assertion( packageT(Package,''​) ),
 + assertion( compilationUnitT(CompilationUnit,​Package,​_FileS,​[],​[Class]) ),
 + assertion( classT(Class,​CompilationUnit,'​HelloWorld',​[],​[_SynteticConstructor,​Field]) ),
 + assertion( fieldT(Field,​Class,​StringType,​message,​null) ),
 + assertion( fully_qualified_name(StringType,​ '​java.lang.String'​ ) ). 
 +</​Code>​
 +
 +Now the test framework will tell us exactly which was the first condition that failed. ​
research/jtransformer/tutorial/testing.txt · Last modified: 2018/05/09 01:59 (external edit)

SEWiki, © 2019