SAP CLASS FOR TESTING ABAP Statements



Get Example source ABAP code based on a different SAP table
  


• FOR TESTING CLASS

CLASS, FOR TESTING
Short Reference

ABAP_SYNTAX
CLASS class DEFINITION FOR TESTING $[RISK LEVEL ${CRITICAL$|DANGEROUS$|HARMLESS$}$]
$[DURATION ${SHORT$|MEDIUM$|LONG$}$].

ABAP Addition
1 ... RISK LEVEL ${CRITICAL$|DANGEROUS$|HARMLESS$}
2 ... DURATION ${SHORT$|MEDIUM$|LONG$}

What does it do?
The FOR TESTING addition defines a class to be used in ABAP Unit. A class with the FOR TESTING addition can have different purposes:
Test class in a narrower sense. A test class contains test methods that are called by the ABAP Unit framework during a test run.
Represent a test double for use as dependent-on component in unit tests. For more information, see Managing Dependencies with ABAP Unit.
Provide helper functions (test infrastructure) for writing ABAP unit tests.
A test class and its components cannot be addressed in the production code of the program therefore, only in other test classes. In particular, a subclass of a test class must be a test class itself and be declared using the FOR TESTING addition. The only exception to this rule is that test classes can be specified as friends in the definition of production classes to make it possible to test private components.
A local test class can contain special private methods that implement the fixture for the tests of the class. These methods have the following predefined names:
An instance method setup, which is executed before each individual test that is before each execution of a test method of a class.
An instance method teardown, which is executed after each individual test that is after each execution of a test method of the class.
A static method class_setup, which is executed once before all tests of the class.
A static method class_teardown, which is executed once after all tests of the class.
The source code of a test class is not part of the production code of its program and is not generated in production systems
BEGIN_SECTION VERSION 5 OUT (controlled using the profile parameter abap/test_generation)
END_SECTION VERSION 5 OUT . The code of such a class is not counted in code coverage measurements.



Latest notes:

Local test classes of class pools and function pools should only be