CLASS - FOR TESTING
Short Reference
ABAP Syntax CLASS class DEFINITION
FOR TESTING [RISK LEVEL {CRITICAL|DANGEROUS|HARMLESS}]
[DURATION {SHORT|MEDIUM|LONG}].
ABAP_ADDITIONS:
1 ... RISK LEVEL {CRITICAL|DANGEROUS|HARMLESS}
2 ... DURATION {SHORT|MEDIUM|LONG}
What does it do? The FOR TESTING addition is used to defined a
class as a test class for the
ABAP Unit tool. Test classes can contain
test methods that are called as
individual tests during a test run .
A test class is usually a local class. The source code in a test class
is not part of the production code of the program and is not generated
in production systems (controlled using the
profile parameter
abap/test_generation ). 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 or before each execution
of a test method.
An instance method teardown , which is executed after each
individual test or after each execution of a test method.
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
every test of the class.
Latest notes: Create test classes for class pools and function groups
only in the test includes designed for
them. In other programs, these tests should run at the end of the
program.
In addition to the test methods and special methods for the fixture, a
test class can also contain other components. These components can be
used in a user's own test class only or in other test classes, depending
on the visibility. In this way, help methods can be defined for tests,
for example.
All components required for tests in the context of ABAP Unit should
be defined exclusively in test classes. This ensures that they are not
generated in production systems and cannot be addressed by production
code. Alongside test classes with test methods, this also includes test
dummies and other helper classes that do not contain test methods.
Test classes can inherit from any other classes, in particular from
global classes. This allows general global tests to be implemented that
can be used in local test classes.
Global test classes can be created for reusing complex test
preparations. Global test classes should always be abstract and can only
be used in local test classes. Currently, all instance methods of a
global test class are automatically test methods.
In test classes, the addition
PARTIALLY IMPLEMENTED of the statement INTERFACES can be
specified, which allows interfaces to be implemented only partially.
This is particularly useful in test doubles.
The addition FOR TESTING in a local class created in the area
for local types of the class pool of a global test class. The
addition is not needed in auxiliary classes for the global test class,
since its property test class has an effect on the entire class
pool with regard to its generation. In rare cases in which a global test
class is to be tested itself, local test classes can be created as
recommended for other global classes in the area
local test classes
.
ABAP_ADDITION_1 ... RISK LEVEL {CRITICAL|DANGEROUS|HARMLESS}
ABAP_ADDITION_2 ... DURATION {SHORT|MEDIUM|LONG}
What does it do? These additions assign test
properties to a test class. RISK LEVEL defines the risk level
for a test and DURATION the expected execution time. The test
properties are checked during when the test is executed.
Tests whose risk level is higher than allowed in a system are not
executed.
The behavior of tests that run longer than expected is determined by
the run mode and the
runtime monitor .
Latest notes: A risk level must be defined for SAP test classes.
The additions RISK LEVEL and DURATION replace the
pseudo comments for test classes .
Existing pseudo comments are not ignored, but should no longer be used.
Documentation extract taken from SAP system, � Copyright SAP AG. All rights reserved