cancel
Showing results for 
Search instead for 
Did you mean: 

RAP Unit Testing: How to Create a Draft Entity Test Double (Managed Scenario)

zena516
Explorer
0 Kudos
94

Hi,

I have a managed RAP entity with a behavior implementation method that tries to read active and draft entities. I already know it works in practice through testing it in my Fiori app.

In my unit test for the class, I mock the entities using the test double framework and call my method, which should be able to read entities inserted into the cds or sql test double frameworks. For active entities, my method works with no problem and is able to get a READ result.

However, for draft entities, I could not find a way to create them using the test double framework and our READ gets no result. I tried to insert the persistent draft table as a dependency in the CDS test environment and to insert it through the sql test environment instead, as well, but this did not result in a READ result in the method.

The only thing that did work was a workaround/hack to insert the data I wanted into the CDS test environment as an active entity and then execute the EDIT method on it.

I also could not find any tutorial or documentation about this. The only thing I found was a blog post where someone used the same workaround as me:

https://community.sap.com/t5/technology-blogs-by-sap/abap-units-in-abap-restful-programming-model/ba...

But I wanted to know if there is a "best practice" for doing this or if it is actually intended to use the EDIT workaround.

Thank you,
Zena

Accepted Solutions (0)

Answers (0)