OEUnit - Unit Testing Framework |
A DataProvider is a class method inside of a test case, which provides data which is passed
to individual test methods as method parameters.
A test method declares that is requires a DataProvider when it is defined, using the dataProvider
attribute, supplying the name of a DataProvider method as the attribute value.
A class method is defined with the @DataProvider
annotation, with an optional
name
attribute. This method returns an object of type OEUnit.Data.DataProvider
which
contains the data that will be used to repeatedly invoke the test method.
1. Define a test method, with INPUT
parameters for each test variable.
Use the dataProvider
attribute to specify the name of a class method which will provide data
for the test variables.
For example:
ROUTINE-LEVEL ON ERROR UNDO, THROW. USING OEUnit.Assertion.Assert. USING OEUnit.Data.DataProvider. CLASS SimpleTest: @Test (dataProvider=StatusChangeProvider). METHOD PUBLIC VOID AcceptStatusChange(INPUT varStatus AS CHARACTER, INPUT varAccepted AS LOGICAL): DEFINE VARIABLE result AS LOGICAL NO-UNDO. result = Order:ChangeStatus(INPUT varStatus). Assert:AreEqual(result,varAccepted). END METHOD. END CLASS.
2. Add a method to the class which returns a DataProvider object.
Use the @DataProvider
annotation to indicate that the class is a DataProvider method.
For example:
@DataProvider. METHOD PUBLIC DataProvider StatusChangeProvider(): DEFINE VARIABLE dataProvider AS DataProvider NO-UNDO. dataProvider = NEW DataProvider(). dataProvider:FromJSON("~{ ~"data~": [" + "~{ ~"status~": ~"NEW~", ~"accepted~": true}," + "~{ ~"status~": ~"ACCEPTED~", ~"accepted": true}," + "~{ ~"status~": ~"PICKING~", ~"accepted": true}," + "~{ ~"status~": ~"POSTED~", ~"accepted": false}," + "~{ ~"status~": ~"DELIVERED~", ~"accepted": false}," + "~{ ~"status~": ~"CANCELLED~", ~"accepted": true}," + "]}"). RETURN dataProvider. END METHOD.
Important Notes:
DataProvider
class method must match the value of the dataProvider
attribute on the test method, or the @DataProvider
annotation must
have a name
attribute which matches the value of the dataProvider
attribute on the test method.Progress.Lang.Error
is thrown.PUBLIC
STATIC
.@Before
methods are run before each test method invocation.@After
methods are run after each test method invocation.
3. Run the test case as per normal.
4. In the test case results, the test method will be listed multiple times with a separate status per invocation.
Each method annotated with @DataProvider
can specify a name attribute which is used
when searching for a DataProvider method, instead of the method name.
Syntax:
@DataProvider[(name="DataProviderName")].
DataProviderName
The Name of the DataProvider. This name can then be specified by
a test method as its DataProvider, in the dataProvider
attribute
Example:
@Test (dataProvider=StatusChangeProvider). METHOD PUBLIC VOID AcceptStatusChange(INPUT varStatus AS CHARACTER, INPUT varAccepted AS LOGICAL): DEFINE VARIABLE result AS LOGICAL NO-UNDO. result = Order:ChangeStatus(INPUT varStatus). Assert:AreEqual(result,varAccepted). END METHOD. @DataProvider(name=StatusChangeProvider). METHOD PUBLIC DataProvider myDataProvider(): DEFINE VARIABLE dataProvider AS DataProvider NO-UNDO. dataProvider = NEW DataProvider(). dataProvider:FromJSON("~{ ~"data~": [" + "~{ ~"status~": ~"NEW~", ~"accepted~": true}," + "~{ ~"status~": ~"ACCEPTED~", ~"accepted": true}," + "~{ ~"status~": ~"PICKING~", ~"accepted": true}," + "~{ ~"status~": ~"POSTED~", ~"accepted": false}," + "~{ ~"status~": ~"DELIVERED~", ~"accepted": false}," + "~{ ~"status~": ~"CANCELLED~", ~"accepted": true}," + "]}"). RETURN dataProvider. END METHOD.
The DataProvider class provides a range of methods for loading data into the DataProvider.
METHOD PUBLIC LOGICAL FromJSON(INPUT json AS LONGCHAR)
This method is used to load data from JSON text stored in a LONGCHAR.
Notes:
METHOD PUBLIC LOGICAL FromJSONFile(INPUT path AS CHARACTER):
This method is used to load data from JSON text stored in a file. The file path should be provided as the INPUT parameter.
Notes:
METHOD PUBLIC LOGICAL FromXML(INPUT xml AS LONGCHAR)
This method is used to load data from XML data stored in a LONGCHAR.
Notes:
METHOD PUBLIC LOGICAL FromXMLFile(INPUT path AS CHARACTER):
This method is used to load data from XML data stored in a file. The file path should be provided as the INPUT parameter.
Notes:
METHOD PUBLIC LOGICAL FromTempTable(INPUT ttSrc AS HANDLE):
This method is used to load data from an existing temp-table, via the provided HANDLE INPUT parameter.
Notes: