Xpect

Xpect is a unit- and integration-testing framework that stores test data in any kind of text files and is based on JUnit.

The focus of Xpect is on testing Xtext languages and supporting the process of designing Xtext languages.

Read a longer introduction in my blog

Install Xpect via the update site

Xpect is published under the
Eclipse Public License (EPL)

If you find bugs, please
report them using the Github bugtracker

The build is hosted at CloudBees

Professional Support is available via itemis AG

If you have suggestions, fork the project on Github and send me a pull request :)

If you have questions, send me an email to moritz dot eysholdt at itemis dot de

View the Project on GitHub meysholdt/Xpect

Executable specifications for xtext from meysholdt

How to Start Using Xpect

  1. install Xpect via the update site
  2. Let's assume you hava an Xtext-Language you want to test which uses the file extension *.dmodel. If you don't have such a language, get one in Eclipse via File -> New -> Example -> Xtext Examples -> Xtext Domain Model.
  3. If you don't have the language installed, launch a runtime workbench where it is installed.
  4. Create a new Plug-in Project and add org.xpect.xtext.lib, your languages runtime-project (the one with the grammar inside) and your ui-project to the dependencies.
  5. Create a new Junit Test such as:
    package mytest;
    
    import org.junit.runner.RunWith;
    import org.xpect.runner.XpectRunner;
    import org.xpect.xtext.lib.tests.XtextTests;
    
    @RunWith(XpectRunner.class)
    public class MyXtextTests extends XtextTests {
    }
    The class XtextTests is a test suite with predefined tests that ships with Xpect.
  6. Create a file mytest.dmodel.xt inside the same package as the test class. Note that this file has two file extensions. The first one indicates your language and the second one is .xt.
    /* XPECT_SETUP mytest.MyXtextTests END_SETUP */
    
    package pkg1 {
      entity MyEntity1 {
        
        // int should be the java primitive
        // XPECT linkedName at id --> int
        id:int
        
        // String should be from java.lang 
        // XPECT linkedName at String --> java.lang.String
        name:String
        
        // besides "int", we can reference... and we can not reference foooobar
        // XPECT scope at int --> int, String, java.lang.String, boolean, !foooobar, ...
        id:int
        
        // XPECT errors --> "Couldn't resolve reference to JvmType 'integer'." at "integer"
        id:integer
      }
    }
  7. Now you can try and observe the following:
    • If you do a right mouse click onto the file and choose "open with" in the menu, there are three editors available: (1) An Xpect+Xtext editor with highlighting, content assist, etc. for both your language and the Xpect syntax. (2) An Xpect editor with support for the Xpect syntax. (3) The editor for your language that you build.
    • Running the Java class as JUnit test executes the test cases specified in the mytest.dmodel.xt file.
    • If a test fails, double-clicking on it in the JUnit view opens a comparison editor which compares the test's expectation with the actual test result. This eases understanding why a test fails dramatically.
    • In the context menu of a test in the JUnit view, you can select "go to XPECT" to open and select test case in the DSL-File.
  8. Find further examples for the Domainmodel Language here. For a more extensive introduction, see my blog