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


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:

public void person_no_attributes(){

; 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: is missing display name
             .under(Modul.class, "person")
             .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:

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

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

Download / Install

The Eclipse plugin is available on this P2 update site:

The project is hosted on Google Code:


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


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: Logo

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

Google photo

You are commenting using your Google 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 )

Connecting to %s