Documentation View

We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!

ABAPCREATE_OBJECT_FOR_TESTING - CREATE OBJECT FOR TESTING

ABAPCREATE_OBJECT_FOR_TESTING - CREATE OBJECT FOR TESTING

Addresses (Business Address Services)   General Data in Customer Master  
This documentation is copyright by SAP AG.
SAP E-Book

CREATE OBJECT, FOR TESTING

CREATE OBJECT ... FOR TESTING.

Effect

RAP-specific variant of CREATE OBJECT.

For unit tests of an ABAP behavior implementation, an object of the corresponding class must be created using a reference variable declared beforehand. The addition FOR TESTING enables the instantiation of RAP handler classes.

Development guide for the ABAP RESTful Application Programming Model, section Test.

The ABAP behavior pool BP_DEMO_MANAGED_ROOT_2 contains a BP_DEMO_MANAGED_ROOT_2========CCAU. The variable class_under_test is defined in the private section of the class ltc_managed as follows:

CLASS-DATA: class_under_test TYPE REF TO lhc_demo_managed_root2,
...

The method class_setup includes a CREATE OBJECT ... FOR TESTING. statement:

CREATE OBJECT class_under_test FOR TESTING.

Find more details on the unit test implementation, the methods used in this test include, and so on, via the link to the Development guide for the ABAP RESTful Application Programming Model provided above.

The BP_DEMO_MANAGED_ROOT_2========CCIMP contains the validation validate_field. This validation checks the value of a specific field. If the value is higher than specified in the validation implementation, the saving of a RAP BO instance fails. The test class contains a basic unit test which includes the method validate_field. The method is provided with mock data. In this case, the field value that is checked with the validation validate_field is set that the saving of an instance does not fail.

To show the unit test result, execute the unit test.

To show a failed unit test, you can set the value of data_field4_root provided in the validate_field method implementation to a value greater than the specified threshold in the behavior pool or uncomment the definition and implementation of method validate_field_fails.






Vendor Master (General Section)   Vendor Master (General Section)  
This documentation is copyright by SAP AG.

Length: 3324 Date: 20230201 Time: 103947     sap01-206 ( 59 ms )