Eclipse Labs Xtext Utils: Unit Testing helpers released

On Jul 28th we released a first version of our Xtext Unit Testing utilities. It supports makes unit-testing of Xtext-based grammars a no-brainer!!

Integration-style testing of files

image

A integration-style test covers many of the aspects you want to test, when writing new (test-first), or changing grammars (regression).

A simple test like this one:

@Test
public void person_no_attributes(){
    testFile("person_no_attributes.dmodel");
}

; will cover following functionality:

  • Model file parsed into EMF-model with no errors
  • All cross-references resolved
  • Validation passed; no warnings, no errors.
  • Serializer runs without errors
  • Formatter runs without errors
  • Serialize+Format exactly matches the input-files’ content

Further capabilities (need documentation!)

  • Fluent-API for validation assertion. Example:
// error line 1: person.name-feature is missing display name
assertConstraints(
  issues.errorsOnly()
             .inLine(1)
             .under(Modul.class, "person")
             .named("name")
             .oneOfThemContains("missing display name")
);
  • Switches for turning on/off serialization and formatter

Unit-testing of Parser- or Lexer-Rules

I’ll just show an example here:

@Test
public void id(){
    testTerminal("bar", /* token stream: */ "ID");
    testTerminal("bar3", /* token stream: */ "ID");
    
    testNotTerminal("3bar", /* unexpected */ "ID");
    
    // token streams with multiple token
    testTerminal("foo.bar", "ID", "'.'", "ID");
}

@Test
public void qualifiedNameWithWildcard(){
    testParserRule("foo.*", "QualifiedNameWithWildCard");
}

Download / Install

The Eclipse plugin is available on this P2 update site: http://xtext-utils.eclipselabs.org.codespot.com/git.distribution/releases/unittesting-0.9.x

The project is hosted on Google Code:

Source: http://code.google.com/a/eclipselabs.org/p/xtext-utils/source/checkout?repo=unittesting

Unit-Testing Documentation: Unit_Testing – xtext-utils – Unit testing – A collection of useful utilities and samples for Xtext based projects – Google Project Hosting

Advertisements

6 thoughts on “Eclipse Labs Xtext Utils: Unit Testing helpers released

  1. Great! … but what is the relationship of Xtext Utils with generated test project when you create a new Xtext project?

    – AT

      • Thank you for the response. But, the structure and contents of test project of a DomainModel (which comes with Xtext 2.0 as one of sample projects) looks different from those of Xtext Utils. Is Xtext Utils the future direction?

        – AT

      • If I remember right, we just added things to the example. The test base class is a different one, though.
        The tested models are added to a resource folder (on classpath)

        So far this is Eclipse Labs. If customers like it, we’d be happy to donate it to Eclipse.

        Although, i think we need tighter release cycles for the testing stuff. So, we’ll see.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s