Example: Integrate EUnit into a standard JUnit plug-in test

package org.eclipse.epsilon.examples.eunit.junit;

import java.io.File;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.common.util.URI;
import org.eclipse.epsilon.emc.emf.EmfModel;
import org.eclipse.epsilon.eol.exceptions.models.EolModelLoadingException;
import org.eclipse.epsilon.eol.execute.operations.contributors.OperationContributor;
import org.eclipse.epsilon.eol.models.IModel;
import org.eclipse.epsilon.etl.EtlModule;
import org.eclipse.epsilon.eunit.junit.IEUnitSuite;
import org.eclipse.epsilon.eunit.junit.dt.EclipseEUnitTestRunner;
import org.junit.runner.RunWith;

 * Example EUnit-based JUnit plug-in test suite which uses a custom contributor
 * to invoke an ETL transformation from an EUnit test suite. This custom
 * contributor is required since running an Ant script from a JUnit plug-in test
 * (from Tycho, for instance) is quite difficult to set up.
public class JUnitIntegrationExampleSuite implements IEUnitSuite {

  public static final class ExampleTestOperationContributor extends
      OperationContributor {
    public boolean contributesTo(Object target) {
      return true;

    public void transform() throws Exception {
      EtlModule etl = new EtlModule();
      etl.parse(new File("resources/etl/Tree2Graph.etl"));

  public OperationContributor getOperationContributor() {
    return new ExampleTestOperationContributor();

  public java.net.URI getModuleURI() throws Exception {
    return getResourceURI("tests/example.eunit");

  public List<IModel> prepareModels() throws Exception {
    final List<IModel> models = new ArrayList<IModel>();
    models.add(loadEmptyModel("Tree", "metamodels/tree.ecore"));
    models.add(loadEmptyModel("Graph", "metamodels/graph.ecore"));
    models.add(loadEmptyModel("GraphExpected", "metamodels/graph.ecore"));

    return models;
  }private EmfModel loadEmptyModel(String name, String metamodelPath) throws EolModelLoadingException {
    EmfModel model = new EmfModel();
    model.setModelFileUri(URI.createFileURI(new File("Empty" + name + ".model").getAbsolutePath()));
    return model;

  private java.net.URI getResourceURI(String resourcePath) throws URISyntaxException {
    return getClass().getResource("/resources/" + resourcePath).toURI();

  private URI getResourceEmfURI(String resourcePath) {
    return URI.createURI(getClass().getResource("/resources/" + resourcePath).toExternalForm());

operation emptyToEmpty() {
  assertEqualModels("Graph", "GraphExpected");

operation oneNodeToRoot() {
  var t = newRoot('A');
  var g = new GraphExpected!Graph;
  assertEqualModels("Graph", "GraphExpected");

operation twoLevels() {
  var root = newRoot('A');

  var g = new GraphExpected!Graph;
  var gMain = g.newNode('A');

  assertEqualModels("Graph", "GraphExpected");

operation newRoot(label : String) : Tree!Tree {
  var t = new Tree!Tree;
  t.label = label;
  return t;

operation Tree!Tree newChild(label : String) : Tree!Tree {
  var child = new Tree!Tree;
  child.label = label;
  child.parent = self;
  return child;

operation GraphExpected!Graph newNode(name : String) : GraphExpected!Node {
  var node = new GraphExpected!Node;
  node.name = name;
  return node;

operation GraphExpected!Node linkTo(target : GraphExpected!Node) : GraphExpected!Edge {
  var edge = new GraphExpected!Edge;
  edge.source = self;
  edge.target = target;
  return edge;

operation GraphExpected!Node newChild(label : String) : GraphExpected!Node {
  var node = self.eContainer.newNode(label);
  return node;
rule Tree2Node 
  transform t : Tree!Tree
  to n : Graph!Node {
  n.name = t.label;
  if (t.parent.isDefined()) {
    var e : new Graph!Edge;
    e.source ::= t.parent;
    e.target = n;
  else {
      // root node: create root element for the graph model
      new Graph!Graph;

    // add node to graph

Clone Epsilon's Git repository:

  • navigate to examples
  • import the org.eclipse.epsilon.eunit.examples.junit project

Once you have checked out/imported the code, to run the example you need to go through the following steps:

  1. register any .ecore metamodels in the org.eclipse.epsilon.eunit.examples.junit project
  2. right click the .launch file in the org.eclipse.epsilon.eunit.examples.junit project
  3. select Run as... and click the first item in the menu that pops up

What's this?

In this example we show how to write an EUnit/JUnit plug-in test of an ETL transformation.

What are .emf files?

.emf files are Ecore metamodels expressed using the Emfatic textual syntax.

More examples...

Epsilon Object Language
Epsilon Transformation Language
Epsilon Generation Language
Epsilon Validation Language
Epsilon Merging Language
Epsilon Flock
Epsilon Model Generation Language
Epsilon Pattern Language
Combining the Epsilon Languages

Even more examples...

More examples are available in the examples folder of the Git repository.