OEUnit - Unit Testing Framework |
A test case is a class containing one or more Test methods.
Important Notes:
ROUTINE-LEVEL ON ERROR UNDO, THROW
statement.
Not using this statement can cause test failures to be recorded as passes.OEUnit.Assertion.Assert
class.
1. Create an empty class like the class below SimpleTest.cls
:
ROUTINE-LEVEL ON ERROR UNDO, THROW. USING OEUnit.Assertion.Assert. CLASS SimpleTest: END CLASS.
2. Add a test method to the class:
ROUTINE-LEVEL ON ERROR UNDO, THROW. USING OEUnit.Assertion.Assert. CLASS SimpleTest: @Test. METHOD PUBLIC VOID IntegerTest(): DEFINE VARIABLE myInt AS INTEGER NO-UNDO INIT 0. Assert:AreEqual(myInt,0). /* Passes */ END METHOD. END CLASS.
3. To run the test case, see Running a Test.
Each method annotated with @Test
is run as a single atomic test by
the test runner, and its result is recorded. Test methods typically make a number
of assertions.
Syntax:
@Test[([expected="ErrorTypeName"][,dataProvider="DataProviderMethod"])].
ErrorTypeName
The Type-Name of a class that inherits from Progress.Lang.Error
.
Informs the test runner that an error of this type is expected to be thrown by this
Test method. If the expected error is thrown, the test passes, otherwise the test
fails.
DataProviderMethod
The name of a method that has been defined with a @DataProvider annotation.
For more information on DataProviders, see Data Providers.
Examples:
1. A simple test method:
@Test. METHOD PUBLIC VOID Example(): Assert:IsTrue(TRUE). Assert:IsFalse(FALSE). END METHOD.
2. A test method expecting an error to be thrown:
@Test(expected="Progress.Lang.AppError"). METHOD PUBLIC VOID ExampleExpectingError(): RETURN ERROR NEW Progress.Lang.AppError(). /* Passes */ END METHOD.
Important Notes:
\src\OEUnit\Assertion\Assert.cls
for full list of the assertion
methods available.Progress.Lang.Error
is thrown.Progress.Lang.Error
thrown while running a Test method will be
recorded as a failure, unless the error is expected as defined by the 'expected'
attribute of the @Test
annotation (see syntax above).PUBLIC
STATIC
.
Methods annotated with @Before
are run before each single Test method.
Before methods are useful for setting up a test fixture before each test.
Syntax:
@Before.
Example:
@Before. METHOD PUBLIC VOID CreateResources(): objUsedDuringTest = NEW SomeTestObject(). END METHOD.
Important Notes:
PUBLIC
and accept no parameters.STATIC
.
Methods annotated with @After
are run after each single test method.
After methods are useful for cleaning up a test fixture after a Test method has
been run.
Syntax:
@After.
Example:
@After. METHOD PUBLIC VOID DeleteResources(): DELETE OBJECT objUsedDuringTest NO-ERROR. END METHOD.
Important Notes:
PUBLIC
and accept no parameters.STATIC
.
Methods annotated with @BeforeClass
are run before any test method
of the test case. BeforeClass methods are useful for setting up a test fixture before
the first test method is run.
Syntax:
@BeforeClass.
Example:
@BeforeClass. METHOD PUBLIC VOID CreateResources(): objUsedDuringAllTests = NEW SomeTestObject(). END METHOD.
Important Notes:
PUBLIC
and accept no parameters.STATIC
.
Methods annotated with @AfterClass
are run after all test methods in
the test case have been run. AfterClass methods are useful for cleaning up a test
fixture after the last Test method has been run.
Syntax:
@AfterClass.
Example:
@AfterClass. METHOD PUBLIC VOID DeleteResources(): DELETE OBJECT objUsedDuringAllTests NO-ERROR. END METHOD.
Important Notes:
PUBLIC
and accept no parameters.STATIC
.
Test cases and Test methods annotated
with @Ignore
will not be run by the test runner. The @Ignore
annotation is useful for temporarily disabling test cases and test methods.
Syntax:
@Ignore.
Examples:
1. Ignore a test method:
@Test. @Ignore. METHOD PUBLIC VOID Example(): Assert:IsTrue(TRUE). END METHOD.
2. Ignore an entire test case:
ROUTINE-LEVEL ON ERROR UNDO, THROW. USING OEUnit.Assertion.Assert. @Ignore. CLASS MyTestCase: @Test. METHOD PUBLIC VOID IsNotRun(): Assert:IsTrue(TRUE). END METHOD. END CLASS.