Lifecycle of ABLUnit framework
- Last Updated: March 30, 2020
- 4 minute read
- OpenEdge
- Version 12.2
- Documentation
The ABLUnit testing framework uses annotations to specify that a method in a test class or an internal procedure in a test procedure is a test case.
The @Test annotation is used to mark a method or internal
procedure as a test case. The testing framework identifies the test case using the
@Test annotation and executes the test case.
The scope of a test case is defined inside a test class or test procedure. A
test class or procedure is annotated using @Before and
@After.
- If a method or procedure marked with
@Beforeannotation is present, it is executed before any test cases. - If a method or procedure marked with
@Afterannotation is present, it is executed after executing all the test cases. - For each test method or procedure:
@Setupannotated method or procedure is executed, if there is any.- The test method or procedure is executed.
@TearDownannotated method or procedure is executed, if there is any.
Updates to ABLUnit
OpenEdge.ABLUnit namespaces may need to be recompiled or updated to
use the new public API (classes and methods). The following changes require the
modification and removal of a number of public members:- Methods with lifecycle annotations
- Lifecycle method failure and error reporting
errNumkey for expected error numbers- Failure and errors written to
results.xml <skipped>element for ignored tests- Stop conditions caught
<properties>element for test suites@Testsuiteor@Testannotations required
results.xml file is consistent with the JUnit
results standard.Methods with lifecycle annotations
The ABLUnit test framework has the concept of lifecycle methods that add behavior to test cases and individual tests, for instance, code that must run before each test method. Previous releases allowed multiple methods with the same annotation to be run, but at run time, only a single lifecycle method was run.
Now, all of the methods that have lifecycle annotations are run in
the order in which they are defined. Methods must all have the same signature
(return void, no parameters), but the OOABL
class requires the methods to have different names.
Setup_A
and Setup_B both run before Test1 runs.
|
In order for multiple methods with lifecycle annotations to be run, additional behavior changes were made.
Lifecycle method failure and error reporting
A test that returns OpenEdge.Core.AssertionFailedError is a failure because a
particular assertion was tested. All other conditions raised are considered
errors.
If a test method has one or more lifecycle methods, and one of those methods (either the test method itself or one or more of the lifecycle methods) raises any error, then the most severe condition raised is reported. For example, if the test method raises a failure due to an assertion failing, and the lifecycle method raises an error, then the error is reported because an error is more severe than a failure.
errNum key for expected error numbers
@Test annotation enables
developers to specify the type of exception raised using an expected key with an
OOABL type name value. To specify an error
number, use the errNum key. The value for
errNum must be an integer. The test passes
if the following are true: - The test raises an exception, and the exception matches the expected type.
- An
errNumvalue is provided. - The exception's first error number equals the
errNumvalue.
If no errNum key is provided,
then only the expected type is used to determine a test's success.
For example, the following test passes because it does not expect the class to exist.
|
Failures and errors written to result.xml
A single test may have zero, one, or more lifecycle methods associated with
it. The @Setup and @TearDown methods run before and after each test method,
respectively. Failures or errors resulting from the test method or its lifecycle
methods each have a failure or error element created in the results.xml file.
For example, there are two failures in the test named test3:
|
<skipped> element for ignored tests
If a test is ignored, then a <skipped>
element is added with a message attribute.
|
Stop conditions caught
ABLUnit handles stop conditions raised in test methods
(explicitly or implicitly). The message written to the results.xml varies depending on the value of the -catchStop parameter.
If the -catchStop parameter has a value of
0, then the Progress.Lang.AppError error is
raised and caught, and the message "stop condition raised for
<test-name>" is added as an error to the test
result.
If the -catchStop parameter has
a value of 1, then the Progress.Lang.Stop
exception is caught, and an error message is added to the test results. The
message is typically "Stop condition raised" except for lock conflicts. If there
is a lock conflict, then the message is "Lock conflict raised".
<properties> element for test suites
A <properties> element is added to
<testcase> (test classes and procedures)
<testsuite> elements. This element contains a number of
properties that describe the session.
The following is a list of properties and the ABL functions or attributes used to determine their values:
|
@TestSuite or @Test annotation required
@TestSuite annotation or at least one @Test annotation are considered tests, and are added to the list of tests
to run. All other programs are ignored by the ABLUnit test runner.