Skip to content

Latest commit

 

History

History
60 lines (41 loc) · 2.15 KB

db-access-in-ut.md

File metadata and controls

60 lines (41 loc) · 2.15 KB

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:

  • SELECT
  • INSERT
  • UPDATE
  • MODIFY
  • DELETE
  • ROLLBACK
  • COMMIT
  • ALTER

2. RISK LEVEL DANGEROUS or RISK LEVEL CRITICAL

The check reports:

  • UPDATE
  • MODIFY
  • DELETE
  • ALTER

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_ENVIRONMENT
  • CL_OSQL_TEST_ENVIRONMENT
  • IF_CDS_TEST_ENVIRONMENT
  • CL_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

Further Readings & Knowledge