abap-unit-testinglisted
Install: claude install-skill williamcorrea23/sap-router-skill
# ABAP Unit Testing
Guide for writing effective ABAP Unit tests including test class setup, assertions, test doubles, mocking frameworks, and test environments for CDS, SQL, and RAP.
## Workflow
1. **Determine the testing goal**:
- Testing business logic in a class method
- Testing a CDS view entity
- Testing a RAP BO behavior implementation
- Testing database-dependent logic with SQL test doubles
- Setting up test doubles for external dependencies
2. **Choose the right approach**:
- Direct unit test for pure logic (no dependencies)
- Constructor/setter injection for mockable dependencies
- CDS test environment for CDS view tests
- OSQL test environment for SQL-dependent code
- RAP BO test doubles for RAP behavior tests
3. **Follow the AAA pattern**: Arrange → Act → Assert
4. **Ensure test isolation**: Tests must not depend on persistent data or external systems
## Test Class Fundamentals
### Test Class Definition
```abap
"! Test class for ZCL_MY_CLASS
CLASS ltc_my_class DEFINITION FINAL FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
DATA cut TYPE REF TO zcl_my_class. "Class Under Test
CLASS-METHODS class_setup. "Once before all tests
CLASS-METHODS class_teardown. "Once after all tests
METHODS setup. "Before each test
METHODS teardown. "After each test
METHODS test_calculate_total FOR TESTING.
METHODS test_validate_input FOR TESTING.
METHODS test_emp