cancel
Showing results for 
Search instead for 
Did you mean: 

cl_cds_test_environment for nested CDS views

Benedikt3
Participant
0 Kudos
247

i try to mock I_BillingDocument for tests,
but this works only for selects on I_BillingDocumentBasic and not at the root.

Can anyone tell me how to make select work based on I_BillingDocument? We are on HANA 2021.

 go_cds = cl_cds_test_environment=>create(  i_for_entity      = 'I_BillingDocument' "
                                                I_select_base_dependencies = abap_true ) .
     go_cds->enable_double_redirection( ).
    
     " mock data
     DATA: vbrk_t       TYPE STANDARD TABLE OF vbrk WITH EMPTY KEY.
     vbrk_t = VALUE #( ( vbeln = '1234567890'  ) ).
     go_cds->insert_test_data(  vbrk_t  ).
    
    
     " select - dosen't work
     SELECT billingdocument
        FROM I_BillingDocument
        INTO TABLE @DATA(itest1) UP TO 10 ROWS.
    
     " works
     SELECT billingdocument
        FROM I_BillingDocumentBasic
        INTO TABLE @DATA(itest2) UP TO 10 ROWS.

 

View Entire Topic
alex_frank
Product and Topic Expert
Product and Topic Expert

The CDS Test Double Framework doubles the dependent on entities, not the entity itself. It's intended to test the CDS view itself, as you can see in the help: https://help.sap.com/docs/abap-cloud/abap-development-tools-user-guide/abap-cds-test-double-framewor...

If you want to double a certain CDS view directly, and not its dependencies, you can use the OSQL Test Double Framework. Something like:

DATA billing_docs TYPE STANDARD TABLE OF I_BillingDocument WITH EMPTY KEY.
billing_docs = VALUE #( ( BillingDocument  = '1234567890'  ) ).
DATA(osql_env) = cl_osql_test_environment=>create( VALUE #( ( 'I_BillingDocument' ) ) ).
osql_env->insert_test_data( billing_docs ).