abap-unit-testinglisted
Install: claude install-skill williamcorrea23/sap-router-skill
# ABAP Unit Testing
Automated unit testing framework for ABAP — equivalent to JUnit/NUnit.
## Test Class Structure
```abap
CLASS ztc_material_handler DEFINITION FINAL FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PRIVATE SECTION.
METHODS setup.
METHODS teardown.
METHODS create_material_ok FOR TESTING.
METHODS create_material_duplicate FOR TESTING.
METHODS create_material_fail FOR TESTING.
ENDCLASS.
CLASS ztc_material_handler IMPLEMENTATION.
METHOD setup.
" Initialize test doubles
ENDMETHOD.
METHOD create_material_ok.
" Given
DATA(lv_payload) = 'MAT001'.
" When
DATA(ls_result) = mo_handler->create_material( lv_payload ).
" Then
cl_abap_unit_assert=>assert_equals(
act = ls_result-status
exp = 'SUCCESS' ).
ENDMETHOD.
ENDCLASS.
```
## Risk Levels
| Level | Use Case | Constraints |
|---|---|---|
| HARMLESS | No side effects, read-only | No commit, no RFC to other systems |
| DANGEROUS | May change data | Test data cleanup in teardown |
| CRITICAL | Changes customizing or production data | Requires explicit approval |
## Test Doubles
```abap
" Create test double for logger interface (ABAP 7.50+)
DATA(lo_logger_double) = cl_abap_testdouble=>create( 'ZIF_ZROUTER_LOGGER' ).
" Configure method call
cl_abap_testdouble=>configure_call( lo_logger_double
)->returning( 'ABC123' )->for_method( 'LOG_ACTION' ).
" Inject into class under test
mo_handler = NEW zcl_material_handler( io_logger = lo_logger_dou