Example: Test EOL scripts with EUnit

@test
operation integers() {
  assertEquals(2, 1 + 1);
  assertNotEquals(10, 1 + 1);
}

@test
operation floats() {
  // Floating-point math: 0.01 * 10 is not exactly equal to 0.1
  assertNotEquals(0.1, 0.01 * 10);

  // We need to define an error margin. We use ulps, as in Math.ulp(double).
  // Here we use a margin of 10 ulps around the expected value (0.1). 
  assertEquals(0.1, 0.01 * 10, 10);
}

@test
operation strings() {
  // assertEquals also works with Strings
  assertEquals("A", "A");
  assertNotEquals("A", "B");
}

@test
operation errors() {
  // assertError only passes if an exception is thrown when evaluating its expression
  assertError(null.toString());
}

@test
operation customAssertion() {
  assertStringContainsFoo("FooBar");
  assertError(assertStringContainsFoo("Bar"));
}

operation assertStringContainsFoo(s: String) {
  if (not s.contains("Foo")) {
    fail("String '" + s + "' did not contain Foo");
  }
}
<project>
  <target name="run-tests">
    <epsilon.eunit src="tests.eunit"/>
  </target>
</project>

Check out the code from the SVN:

  • go to the SVN repository
  • navigate to trunk/examples
  • check out the org.eclipse.epsilon.eunit.examples.eol 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.eol project
  2. right click the .launch file in the org.eclipse.epsilon.eunit.examples.eol project
  3. select Run as... and click the first item in the menu that pops up

What's this?

In this example we show the basic structure of an EUnit test, some useful assertions for the basic types and how to test for errors and define our own assertions.

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
Combining the Epsilon Languages
EuGENia
EUnit

Even more examples...

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