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 by TypeFox

Professional Support is available via TypeFox GmbH

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 typefox dot io

View the Project on GitHub meysholdt/Xpect

Hosted on GitHub Pages — Theme by orderedlist

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;
    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 int --> int
        // String should be from java.lang 
        // XPECT linkedName at String --> java.lang.String
        // besides "int", we can reference... and we can not reference foooobar
        // XPECT scope at int --> int, String, java.lang.String, boolean, !foooobar, ...
        // XPECT errors --> "Couldn't resolve reference to JvmType 'integer'." at "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