EGL Unit Testing
Unit testing allows programmers to test individual components of their application (such as functions) without having to run the entire system.
- Test cases - EGL functions that test a service function or library function, or an EGL called program.
- Test suites - a collection of test cases.
- Test fixtures - functions that are invoked before or after every testcase or test suite.
- AssertionLib - an EGL system library that provides assertions to determine the test results.
EUnit handlers are generated as Java JUnit5 testcases. The necessary libraries are added when you select EUnit as an EGL project feature in the project preferences. You can also add the JUnit libraries manually in the Java Build Path preferences.
AssertionLib functions are also supported in EGL Rich UI. The output is written to the browser console. EUnit handlers are not supported.
Creating An EUnit Handler
EUnit handlers can be created in two ways
- New - EUnit Handler Wizard, which will generate a basic EUnit handler.
- Existing - Selecting an existing EGL part, package or project, and choosing Generate EUnit from the context menu. The wizard will show a list of available functions that can be tested with EUnit. Select finish to generate an EUnit handler that will invoke the selected functions.
Running An EUnit Handler
To run an EUnit handler, right click on the generated Java and select “Run As ➔ Junit Test”. The results will be presented in a JUnit view.
EUnit handlers are not supported by the EGL Debugger.
Description Of EUnit Elements
| EUnit element | Type | Example |
| EUnit | Subtype for handler |
|
| RunWith | Property of EUnit, Species the EUnit handler as a test suite |
|
| Test | Annotation for function member of EUnit, specify it is a test case |
|
| enabled | Property for @Test annotation (default is true) |
|
| Title |
Property for @Test annotation (default value is name of function). This is used for JUnit results view |
|
| BeforeEach, AfterEach, BeforeAll, AfterAll | Annotation for function member of Eunit, specify it is a test fixture function |
|
| AssertionLib | EGL built-in library | assertEquals(expectedString, actualString) |
| Suite | Annotation for field member of EUnit, must be an array field |
|
Parameterized Tests
EUnit provides the ability to specify parameters to be used for each testcase, eliminating the need to write a new testcase for each parameter.
EUnit parameters can be specified using a property for the EUnit @Test annotation.
- E.g. @Test{values=[“string1”, “String2”….]}
- @Test{valuesfile=“mycsvfile”}
- csv file is relative to the EUnit’s generated Java package.
AssertionLib
This EGL system library provides assertion functions to determine the outcome of a test case. The following functions are available:
assertTrue(condition boolean in)
- asserts that a condition is true.
assertTrue(condition boolean in, message string? in)
- asserts that a condition is true. If it isn't, the given message is shown for the assertion error.
assertFalse(condition boolean in)
- asserts that a condition is false.
assertFalse(condition boolean in, message string? in)
- asserts that a condition is false. If it isn't, the given message is shown for the assertion error.
assertNull(input any in)
- asserts that the input is null.
assertNull(input any in, message string? in)
- asserts that the input is null. If it isn't, the given message is shown for the assertion error.
assertNotNull(input any in)
- asserts that the input is not null.
assertNotNull(input any in, message string? in)
- asserts that the input is not null. If it is null, the given message is shown for the assertion error.
assertEquals(expected any in, actual any in)
- asserts that two input values are equal.
assertEquals(expected any in, actual any in, message string? in)
- asserts that two input values are equal. If they aren't, the given message is shown for the assertion error.
assertNotEquals(expected any in, actual any in)
- asserts that two input values are not equal.
assertNotEquals(expected any in, actual any in, message string? in)
- asserts that two input values are not equal. If they are equal, the given message is shown for the assertion error.
assertFailure()
- marks a test as failed.
assertFailure(exception egl.core.AnyException in)
- marks a test as failed. The given exception is shown for the failure.
assertFailure(message string? in)
- marks a test as failed. The given message is shown for the failure.