We are hiring and constantly growing! Have a look through our vacancies to find the right role for you!
CREATE OBJECT ... FOR TESTING.
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.
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.