Skip to content

ABAP Keyword Documentation →  ABAP - Reference →  Declarative statemnts →  Classes and Interfaces →  CLASS →  CLASS - DEFINITION →  CLASS - class_options 

CLASS - FOR TESTING

Short Reference

Other versions: 7.31 | 7.40 | 7.54

Syntax


 ... FOR TESTING [RISK LEVEL {CRITICAL|DANGEROUS|HARMLESS}] 
                [DURATION   {SHORT|MEDIUM|LONG}]  ... .

Extras

1. ... RISK LEVEL {CRITICAL|DANGEROUS|HARMLESS}

2. ... DURATION {SHORT|MEDIUM|LONG}

Effect

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 inidividual 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.


Notes

  • 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 your own test class only or in other test classes, depending on the visibility. In this way you can define help methods for tests, for example.
  • Test classes can inherit from any other classes, in particular from global classes. This allows you to implement general global tests that can be used in local test classes.
  • You can create global test classes 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.
  • You cannot use the addition FOR TESTING in a local class that is 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.

Addition 1

... RISK LEVEL {CRITICAL|DANGEROUS|HARMLESS}

Addition 2

... DURATION {SHORT|MEDIUM|LONG}

Effect

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. Tests that run longer than the expected execution time are terminated.


Notes

  • You must define a risk level for SAP test classes.
  • The additions RISK LEVEL and DURATION replace the pseudo comments for test classes. Existing pseudo comments are not ignored, but you should no longer use them.