MGT Testlanguage

Part of the series about a project of mine: MGT

After I wrote about the metamodel for the tests in the last post, it’s easy to present the language now. The language is just an easy to write serialization of the model. The more interesting part is the tooling to derive the language from the model and an editor to use the language. So I start with this first and we’ll see the result at the end.

For deriving the language from the Eore model I used EMFText. For the basic installation and usage have a look at the projects homepage. To define the language one has to add a syntax description for any model element. The descriptions are like EBNF notations. The following snippet shows the ones of MGT:

    TestSuite ::= "TESTSUITE" #1 "{" !1
                        "suiteName"":" name[BIGNAME]"," !1
                        "systemUnderTest"":" systemUnderTest[BIGNAME]"," !1
                        "adapter"":" adapter[IDENTIFIER] !1
    TestCase ::= "TESTCASE" #1 "{" !2
                        "caseName" ":" name[IDENTIFIER] !2
                        (testSteps ";"!1)+ 
    Assertion ::= "ASSERT" assert[IDENTIFIER]"(" actual ("," expected)? ")" (":" 
                    verdict[fail : "FAIL", error : "ERROR", inconclusive : "INCONCL", pass : "PASS"])?;
    UIElementLocator ::= "id" id[IDENTIFIER];
    Keyword ::= name[IDENTIFIER]  (":" target)?  (":" testData ("," testData)*)?  ;
    Sequence ::= "SEQUENCE" #1 name[IDENTIFIER] #1"{" !1
                        (steps ";"!1)+ !0
    SequentialStep ::= "seq:" sequence[IDENTIFIER];
    Integer ::= dataValue[INTEGER];
    Boolean ::= dataValue["true" : "false"];
    String ::= dataValue['"','"'];
    Float ::= dataValue[FLOAT];

I don’t wanna explain the whole thing now so I refer again to the documentation of EMFText or you can compare it to the actual language below.
Besides the syntax you can also define the tokens that are allowed to fill the models properties (text in square brackets, e.g. IDENTIFIER), the token styles and some options for code generation. All that is done in one ‘concrete syntax’ file.

Having a valid cs-file you can start generating code. EMFText will generate three Eclipse Plugins. The first one contains Java-Classes that represent those of the model (EMF itself can also do this). Another Plugin is used to parse text files to models and vice versa. This plugin uses antlr to parse the text. The third plugin provides code to integrate the language into the Eclipse editor, like code completion, run configurations, code styles, validation and so on. To make it more usable one should adapt the third plugin, which I also did and will present in another post.

With those generated Plugins you can configure a new Eclipse environment that allows you to write instances of your metamodel. The following screenshot shows the MGT test (model) editor with validation (errors and warnings) and code completion.
As this is a complex topic don’t hestitate to ask and/or discuss.

Leave a Comment

NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>