Get Example source ABAP code based on a different SAP table
ID CREATE-OBJECT-FOR-TESTING • FOR TESTING CREATE OBJECT
CREATE OBJECT, FOR TESTING>
ABAP_SYNTAX CREATE OBJECT ... FOR TESTING.>
What does it do? 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>.
ABAP_FURTHER_INFO Development guide for the ABAP RESTful Application Programming Model, section Test>.
ABAP_EXAMPLE_ABEXA 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 greater than specified in the validation implementation, a RAP BO instance > cannot be saved. 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. ABAP_NOTE 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>. ABAP_EXAMPLE_END