When a Z* ABAP class is created or changed, perform the following unit test maintenance workflow using the MCP server specified by the user.
On new class creation
- Check whether the class already has a local test class (
CLASS ltcl_... DEFINITION FOR TESTING ... ENDCLASS). - If not, create a local test class named
ltc_<ShortClassName>in the class test include, where<ShortClassName>is the class name without the leadingZprefix and any common suffix (e.g.ZCL_MM_INVOICE_PROCESSOR→ltc_mm_invoice_processor). - Add a
setupmethod and ateardownmethod to prepare and clean up the test fixture. - For each public method in the class, generate two test methods:
test_<method_name>_positive— tests the expected happy-path resulttest_<method_name>_negative— tests a failure, boundary, or invalid-input case
- Each test method must:
- Be annotated with
FOR TESTING RISK LEVEL HARMLESS DURATION SHORT - Follow the arrange → act → assert pattern
- Call the method under test with representative inputs
- Assert the expected result using
CL_ABAP_UNIT_ASSERT(e.g.assert_equals,assert_not_initial,assert_true,assert_subrc) - Include a meaningful
msg=parameter in every assertion
- Be annotated with
- Design the test suite to achieve at least 90% code coverage of the production class. Cover all branches (
IF/ELSEIF/ELSE,CASE,TRY/CATCH) with at least one test each.
On method addition
- Identify all new public methods in the changed class.
- For each new method, add two test methods —
test_<method_name>_positiveandtest_<method_name>_negative— to the existing local test class. - Implement each test body following arrange → act → assert, covering the happy path and at least one failure or boundary case.
- Ensure the expanded test suite still targets ≥90% code coverage of the production class.
- Activate the test include via the MCP server after adding new test methods.
On method change (signature or logic)
- Identify which methods changed (parameters added, removed, renamed, or logic modified).
- Update both
_positiveand_negativetest methods to reflect the new signature or expected behavior:- If parameters were removed → remove them from both test calls
- If parameters were added → supply representative values (valid for positive, invalid/boundary for negative)
- If return type or logic changed → update assertions in both test methods accordingly
- Re-evaluate whether the updated tests still cover ≥90% of the changed method's branches; add additional cases if not.
- Activate the test include via the MCP server after the update.
On method deletion
- Identify which methods were deleted from the source class.
- Remove the corresponding
_positiveand_negativetest methods from the local test class. - If no test methods remain after removal, remove the entire local test class.
- Activate the test include via the MCP server after removal.
General rules
- Always use the MCP server specified by the user for all read and write operations.
- Never modify the production class logic — only touch the test include.
- Use
CL_ABAP_UNIT_ASSERTfor all assertions; never useWRITEorMESSAGEin test methods. - Default annotation for all test methods:
RISK LEVEL HARMLESS DURATION SHORTunless the user specifies otherwise. - Name test class as
ltc_<short_class_name>(strip the leadingZand any generic suffix). - Every public method must have at least one
_positivetest (valid inputs, expected output) and one_negativetest (invalid input, boundary value, or expected exception/error). - Target ≥90% code coverage across all branches of the production class; cover every
IF,ELSEIF,ELSE,CASE, andCATCHblock with at least one test. - After any change, always activate the test include and report success or activation errors.