Dear community,
I am having an error creating a unit test with RAP. I have the following developments objects:
Now I want to create a simple unit test for an determination of the interface view in which test data for entity A and B is necessary. In my test class I create the test environment like the following:
cds_test_environment = cl_cds_test_environment=> cds_test_environment = cl_cds_test_environment=>create_for_multiple_cds(
VALUE #(
( i_for_entity = 'Z_I_ENTITY_A' )
( i_for_entity = 'Z_I_ENTITY_B')
)
).
DATA my_mock_data TYPE STANDARD TABLE OF Z_A_ENTITY_A.
" Fill my_mock_data with test data values
...
" Insert test data
cds_test_environment->insert_test_data( i_data = my_mock_data ).
The insert_test_data statement fails with the following message “The test double ‘Z_A_ENTITY_A’ not found.
When I change the create_for_multiple_cds statement to use the base views, it works. However, I need to test on interface view level. How is this possible? What can I change in order to enable this?
In the documentation of create_for_multiple_cds it says "This parameter should not be used while writing a unit test. For unit test, the framework will automatically evaluate the first level dependencies in the hierarchy and will create doubles for them". This seems like an explanation why it works when creating the test environment on base view level. However, all attempts from my side to fill the dependecy list manually failed. Also, to me it is not clear whether "hierarchy" here refers to the relationship between Entities (like Entity A and B) or the relationship between base views and consumption views.
Any help is highly appreciated!
Request clarification before answering.
I was finally able to solve the problem without by-passing the base view.
@MioYasutakeYou were right to set the parameter i_select_base_dependencies = abap_true. The error I did all along was that I set it only for Entity A not also entity B.
For completness sake, here the pseudo code:
cds_test_environment = cl_cds_test_environment=> cds_test_environment = cl_cds_test_environment=>create_for_multiple_cds(
VALUE #(
( i_for_entity = 'Z_I_ENTITY_A' i_select_base_dependencies = ABAP_TRUE )
( i_for_entity = 'Z_I_ENTITY_B' i_select_base_dependencies = ABAP_TRUE )
)
).
DATA my_mock_data TYPE STANDARD TABLE OF Z_A_ENTITY_A.
" Fill my_mock_data with test data values
...
" Insert test data
cds_test_environment->insert_test_data( i_data = my_mock_data ).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.