EUnit is a framework used to write and run repeatable test cases and to create reports about the results. The framework code is in the org.eclipse.edt.eunit.runtime package.
An interactive process is available for running tests. A batch mechanism is planned to let you run tests automatically; for example, to run tests overnight. However, only the interactive process is in place at this time.
To write test cases, code an EGL library and document it in a way that provides details for display in the output report. A set of library functions implement your test cases, one function per test case.
package common;
import org.eclipse.edt.eunit.runtime.LogResult;
import org.eclipse.edt.eunit.runtime.Test;
import org.eclipse.edt.eunit.runtime.status;
/** @test
* @description Test cases for demonstration
* @keywords Comparisons, Skips
**/
library MyTestCases
function test01() {@Test}
// do processing here, as appropriate for the test case.
a int = 100;
b int = 50;
success boolean = a > b;
LogResult.assertTrue("Test for one integer greater than the other. ", success);
end
function test02() {@Test {targetLang = [Java, JavaScript]}}
// do processing here, as appropriate for the test case.
a string = "first";
b string = "last";
LogResult.assertStringEqual("Test for two equal strings. ", a, b);
end
function test03() {@Test}
// do processing here, as appropriate for the test case.
myTrue boolean = true;
myFalse boolean = true;
// expected myFalse to be false
if (myTrue==myFalse)
LogResult.failed("Failed to distinguish between true and false. ");
else
LogResult.passed("Logic is correct.");
end
end
function test04() {@Test}
LogResult.skipped("Waiting to resolve bug 2525");
return;
// remove the previous two lines when the bug is resolved.
// do processing here, as appropriate for the test case.
end
function test05() {@Test{targetLang = [Java]}}
myException MyExceptionType;
try
// do processing here, as appropriate for the test case.
throw new MyExceptionType{message = "An unexpected exception"};
onException (except AnyException)
LogResult.error(except.message);
end
end
end
Record MyExceptionType type Exception end
If you are comparing one record, handler, or external type to another, invoke a series of LogResult functions, one for each field value of interest.
For details on those functions, see the following EGL Language Reference entry: LogResult external type.
A test driver is a project from which you run the test cases. A test driver is language specific, including only the test cases that were targeted for a given language.
The library-specific report includes a msg: title, and after that title is the content of the logged messages for that library.

The next example demonstrates how to use the TestListMgr library, which includes additional functions that you can ignore because their purpose is to support the EUnit framework.
package server;
Service MyServiceType
function calculate(myScores Int[] in) returns (Decimal(4,2))
numberOfScores, i, mySum Int;
numberOfScores = myScores.getSize();
for (i from 1 to numberOfScores by 1)
mySum = myScores[i] + mySum;
end
return(mySum/numberOfScores);
end
end
package client;
import org.eclipse.edt.eunit.runtime.AssertionFailedException;
import org.eclipse.edt.eunit.runtime.LogResult;
import org.eclipse.edt.eunit.runtime.Test;
import org.eclipse.edt.eunit.runtime.TestListMgr;
import eglx.lang.AnyException;
import server.MyServiceType;
library MyLibrary
function test01(){@Test}
myBindingVar httpProxy;
myList int[] =[2, 3];
call MyServiceType.calculate(myList)
using myBindingVar
returning to theCallBack01
onException theExceptionHandler;
end
function test02(){@Test}
myBindingVar httpProxy;
myList int[] =[2, 3, 4];
call MyServiceType.calculate(myList)
using myBindingVar
returning to theCallBack02
onException theExceptionHandler;
end
function theCallBack01(retResult decimal(4, 2) in, http IHttp)
index int;
try
LogResult.assertDecimalEqual("Problem with Test01", 2.5, retResult);
onException(e1 AssertionFailedException)
TestListMgr.caughtFailedAssertion(e1);
onException(e AnyException)
TestListMgr.caughtAnyException(e);
end
TestListMgr.nextTest();
end
function theCallBack02(retResult decimal(4, 2) in, http IHttp)
index int;
try
LogResult.assertDecimalEqual("Problem with Test02", 3.0, retResult);
onException(e1 AssertionFailedException)
TestListMgr.caughtFailedAssertion(e1);
onException(e AnyException)
TestListMgr.caughtAnyException(e);
end
TestListMgr.nextTest();
end
function theExceptionHandler(exp AnyException in, http IHttp in)
TestListMgr.handleCallBackException(exp, http);
end
end