Writing robust and reliable applications is crucial, and unit testing plays a vital role in achieving that goal. For Progress ABL developers, ABLUnit offers a powerful framework for testing business logic, data access, and utility code. This article provides a comprehensive guide to using ABLUnit effectively, ensuring your applications function as intended.
Test Project Structure
Organize your test project mirroring your main application’s structure. Create separate folders for Business Entities (BE), Data Access (DA), and Utilities, each with a dedicated TestData folder containing mock data for testing. Use JSON or XML files to store this mock data in a format recognized by the dataset you’re working with.
ABL Unit Annotations
Master these five essential annotations:
- @Setup: Runs before each test, ideal for creating objects and populating temp-tables from TestData.
- @TearDown: Runs after each test (success or failure), cleaning up created objects and emptying datasets.
- @Before: Runs once before all tests.
- @After: Runs once after all tests.
- @Test: Marks a method containing assertions to be evaluated by the AVM.
ABLUnit Executions Cycle
1. Inheritance: Start by making your TestClass inherit the behavior of the class you’re testing (e.g., BEAppUser).
2. Setup Phase:
- Create instances for classes with foreign key relationships to the tested class (e.g., UserRole, EmailSettings).
- Populate temp-tables using @Setup and mock data.
3. Test Methods: Read Methods:
- Test ReadAll to ensure returned records match database data in number and structure.
- Test ReadById by creating a record, saving its ID, calling the method, and verifying its structure.
4. Create Methods:
- Test CreateSuccessful by writing, creating, and verifying a record, checking for additional data creation if applicable.
- Test CreateFail with empty mandatory fields or invalid data, catching expected errors with AssertRaiseError.
5. Update Methods:
- Test UpdateSuccessful by creating, updating, and verifying a record.
- Test UpdateFail with invalid updates, catching expected errors and using AssertRaiseError.
6. Delete Methods:
- Test DeleteSuccessful with cascading deletes by creating linked data and verifying its deletion.
- Test DeleteFail with scenarios preventing deletion, catching expected errors and using AssertRaiseError.
7. Other Methods: Test all public and protected methods in your class.
8. Conditional Logic: If a method has IF or CASE statements, create tests for each possible outcome.
Running ABLUnit Tests
Individual Test Class: Right-click the class file and select “Run As > Progress OpenEdge ABLUnit.”
Test Suite:
- Create a new procedure with @TestSuite(classes = “Class1Name.cls,Class2Name.cls, etc..”).
- Run the procedure as “Progress OpenEdge ABLUnit.”
Remember:
- Follow a clear and consistent testing approach.
- Write comprehensive tests covering all functionalities.
- Utilize annotations effectively to manage the testing process.
- Regularly execute tests to ensure code quality and catch regressions.
By following these guidelines and leveraging the power of ABLUnit, you can ensure your Progress ABL applications are well-tested, reliable, and ready to meet the demands of your users.