Test the class
- Last Updated: January 16, 2024
- 2 minute read
- OpenEdge
- Version 12.8
- Documentation
If your class contains more than one version of the constructor, then you should write code to test all of them. If a class constructor takes parameters, you must add code to create instances that test the range of values for that constructor. For example, you must write code to pass in values that are valid and values that are not valid.
Next, in your test procedure, you write code that tests the instance created by a constructor. Depending on the values of the data members of the instance, you must call the relevant methods to confirm that it executes correctly. Along the way, you can use message statements to write data to the output file.
In this example, we call the default constructor to create an instance of the
Emp class. Next, we assign values to the Phones elements and then call the
Initialize() method of the Emp class, passing
values to initialize the instance. The message statement writes information about the
PUBLIC data members of the instance after the Initialize() method has been called.
After this, if there is more to test, you can use the same instance to test other
PUBLIC data members and methods of the class.
block-level on error undo, throw.
using Enterprise.HR.Emp.
// define and initialize the array for holding the phone numbers
var char[3] Phones = ["617-284-5937","508-394-3928","508-294-3927"].
// set up the file for writing data
output to "/testResults/log/testEmp.out".
// Create and initialize the variable for holding the Emp instance
var Emp EmpInstance = new Emp().
EmpInstance:Initialize(99,
"John",
"Doe",
"123 Main Street",
"01730",
Phones,
50,
"Senior Developer").
Message "*********testInitialize()************" skip
EmpInstance:FirstName " "
EmpInstance:LastName " , "
EmpInstance:JobTitle skip
"Emp # " EmpInstance:EmpNum "- Vacation hours: "
EmpInstance:VacationHours skip
EmpInstance:Address " " EmpInstance:PostalCode skip
"Phones: " EmpInstance:Phones[1] " " EmpInstance:Phones[2]
"" EmpInstance:Phones[3] " ".
// more of test procedure