db-access-in-ut.md
September 23, 2022 ยท View on GitHub
code pal for ABAP > Documentation > DB Access in Unit Tests Check
Database Access within Unit-Tests Check
What is the intent of the check?
The check searches for database operations inside ABAP Unit test classes that do not use an SQL test double framework to mock the database. Unit tests should usually be isolated from the actual database.
How does the check work?
The check behaves differently depending on the test class's risk level:
1. RISK LEVEL HARMLESS or not set
The check reports:
SELECTINSERTUPDATEMODIFYDELETEROLLBACKCOMMITALTER
2. RISK LEVEL DANGEROUS or RISK LEVEL CRITICAL
The check reports:
UPDATEMODIFYDELETEALTER
3. Test Frameworks
If an instance of one of the following types associated with a test double framework is used in the test class, no findings are reported for database accesses:
IF_OSQL_TEST_ENVIRONMENTCL_OSQL_TEST_ENVIRONMENTIF_CDS_TEST_ENVIRONMENTCL_CDS_TEST_ENVIRONMENT
How to solve the issue?
Isolate the database dependency using one of the test double frameworks for SQL and CDS accesses:
What to do in case of exception?
In special cases, it is possible to suppress a finding by using the pseudo comment "#EC DB_ACCESS_UT.
The pseudo comment must be placed right after the statement that accesses the database.
SELECT * FROM tadir INTO TABLE @DATA(entries). "#EC DB_ACCESS_UT