Require Explicit DURATION and RISK LEVEL Attributes on Test Classes
Overview
Require DURATION and RISK LEVEL attributes on test classes.
ATC Finding Message:
Test class must declare DURATION and RISK LEVEL attributes
Rationale
ABAP Unit test classes (FOR TESTING) should declare explicit DURATION (SHORT, MEDIUM, or LONG) and RISK LEVEL (HARMLESS, DANGEROUS, or CRITICAL) attributes on their CLASS ... DEFINITION statement. Without explicit attributes, the test runner assigns default values that may cause tests with external dependencies or database commits to execute in restricted test environments or time out prematurely.
Best Practice: Always declare DURATION SHORT RISK LEVEL HARMLESS for fast, hermetic unit tests.
Non-Compliant
" Anti-pattern: Test class without duration or risk level attributes
CLASS lcl_order_test DEFINITION FOR TESTING.
PUBLIC SECTION.
METHODS test_calculation FOR TESTING.
ENDCLASS.Compliant
" Clean ABAP: Explicit duration and risk level declaration
CLASS lcl_order_test DEFINITION FOR TESTING
DURATION SHORT
RISK LEVEL HARMLESS.
PUBLIC SECTION.
METHODS test_calculation FOR TESTING.
ENDCLASS.Configuration & Thresholds
This check can be fine-tuned directly in the ATC Check Variant Editor (CHKV) in Eclipse ADT:
| Parameter Name | Data Type | Default Value | Description & Guidance |
|---|---|---|---|
CHECK_DURATION | Boolean | true | Require explicit DURATION attribute (SHORT, MEDIUM, LONG) |
CHECK_RISK_LEVEL | Boolean | true | Require explicit RISK LEVEL attribute (HARMLESS, DANGEROUS, CRITICAL) |
Suppression
To suppress findings for this rule, append the pseudo-comment to the statement:
" Standard pseudo-comment:
... "#EC PREF_TEST_ATTR
" SAP CI_ prefix format:
... "#EC CI_PREF_TEST_ATTRRelated Rules
- Avoid Native ASSERT in Production Code (Prevent Unrecoverable Dumps) —
#EC NO_PROD_ASSERT - Design for Inheritance or Prohibit It (FINAL) —
#EC PREF_FINAL_CLASS
Technical Details
- Native ATC Class:
ZCL_SKYLINT_PREF_TEST_ATTR - Implementation File: zcl_skylint_pref_test_attr.clas.abap