Skip to content
Lieven De Foor edited this page Aug 23, 2017 · 8 revisions

Basic Usage

  • First, ensure that you have read and followed the Installation instructions and that you have included the OEMock directory on your PROPATH.
  • In each test class where you want to use OEMock, include the OEMock package:
USING OEMock.*.
  • Use the OEMock static object inside your test class to create a Mock or Stub object.
    • Further information on each of these classes is shown below
  • Once the test double object(s) has been created and configured, call the Generate() method once on each test double.
    • A temporary directory structure, with temporary files, will be created at this point, and placed at the front of the session's PROPATH.
  • After your test is complete, either successfully or unsuccessfully, delete any test doubles created.
    • IF VALID-OBJECT(myMockObject) THEN DELETE myMockObject.
  • At the end of all tests in the class, call the static method OEMock.CleanUp().
    • This will delete any remaining temporary files, the temporary directory structure, and remove any changes made to the PROPATH value.

Stub Test Doubles

Stub test doubles can be created using the static class methods OEMock:StubProcedure(). and OEMock:StubClass().

  • Each method accepts one character input, giving the file name to be Stubbed.
    • N.B. Ensure that the file name is a relative path file name from the PROPATH.
      • For example: OEMock:StubClass('Billing/TaxCalculator.cls). not OEMock:StubClass('c:/myapp/Billing/TaxCalculator.cls'). (assuming 'c:/myapp/' is on the PROPATH.)
  • Each method will return an object of type OEMock.Stub.
  • Output parameter values for a method, procedure or function can be specified using the methods:
    • SetProcedureOutputParameterValue
    • SetFunctionOutputParameterValue
    • SetMethodOutputParameterValue
    • SetFunctionReturnValue
    • SetMethodReturnValue
  • Details of these methods can be found in the class reference for the Stub class.

Mock Test Doubles

Mock test doubles can be created using the static class methods OEMock:MockProcedure(). and OEMock:MockClass().

  • Each method accepts one character input, giving the file name to be Mocked.
    • N.B. Ensure that the file name is a relative path file name from the PROPATH.
      • For example: OEMock:MockClass('Billing/TaxCalculator.cls). not OEMock:MockClass('c:/myapp/Billing/TaxCalculator.cls'). (assuming 'c:/myapp/' is on the PROPATH.)
  • Each method will return an object of type OEMock.Mock.
  • Output parameter values for a method, procedure or function can be specified using the methods:
    • SetProcedureOutputParameterValue
    • SetFunctionOutputParameterValue
    • SetMethodOutputParameterValue
    • SetFunctionReturnValue
    • SetMethodReturnValue
  • Details of these methods can be found in the class reference for the Mock class.
  • Expectations can be added to Mocked methods, procedures or functions by calling the Expect method on a Mock object.
    • This will return an object of type OEMock.Expectation.Expectation
    • Use the following methods to set expectations regarding the number of times a method, procedure or function is called:
      • CalledAtLeast(integer)
        • Validates the number of times the method, function or procedure is called is more than or equal the value of the integer parameter.
      • CalledAtMost(integer)
        • Validates the number of times the method, function or procedure is called is less than or equal to the value of the integer parameter.
      • CalledAtExactly(integer)
        • Validates the number of times the method, function or procedure is called is exactly the value of the integer parameter.
      • CalledOnlyOnce()
        • Validates the number of times the method, function or procedure is exactly once.
      • NeverCalled()
      • Validates that the method, function or procedure is never called.
    • Details of these methods can be found in the class reference for the Expectation class.

Work Arounds for OpenEdge Limitations

OEMock inpects objects by using a compiled XML-XREF file of the code file that you wish to produce a test double for. Due to limitations in the data that is exported into this file, certain objects cannot be identified from these files.

Currently, the known list of items not exported is:

  • Temp-Tables
    • Including all field and index definitions
  • Parameters defined in the Main Block of a procedure file.

In order for test doubles to function correctly, it is important that these objects are defined in the generated test doubles. Unfortunately, this needs to be done by the code that creates the test double, before it is generated.

Procedure Parameters

The following methods are available inside of any test double for defining parameters in the Main Block of a procedure file.

  • AddProcedureParameter(CHARACTER, CHARACTER, CHARACTER)
  • AddProcedureBufferParameter(CHARACTER, CHARACTER)
  • AddProcedureDataSetParameter(CHARACTER)

Further details can be found in the class references for the Stub and Mock classes.

Temp-Tables

The following methods are available inside of any test double for defining temp-tables within the Main Block of a procedure file, or within a Class declaration.

  • AddTempTable(HANDLE)

Further details can be found in the class references for the Stub and Mock classes.

Clone this wiki locally