• Part1 – how to test odata service generated by CDS view
  • Part2 – what objects are automatically generate after you activate one CDS view
  • Part3 – how is view source in Eclipse converted to ABAP view in the backend
  • Part4 – how does annotation @OData.publish work
  • Part5 – how to create CDS view which supports navigation in OData service
  • Part6 – consume table function in CDS view
  • Part7 – unveil the secret of @ObjectModel.readOnly
  • Part8 – my summary of different approaches for annotation declaration and generation
  • Part9 – cube view and query view
  • Part10 – How does CDS view key user extensibility work in S4
  • Part11 – this blog
  • Part12 – CDS view source code count tool
  • Part13 – CDS view authorization
  • Part14 – CDS view performance analysis using PlanViz in HANA studio

There is a wonderful blog Introduction to CDS Test Double Framework – How to write unit tests for ABAP CDS Entities? written by Sunil Bandameedapalli.

For me, the CDS view test double framework works as a magic for me: how the mocked data I inserted into the view under test could be read again in unit test code? As a result in this blog I will try to explain how CDS view framework works under the hood.

The view I am developed is listed below, which is simply used to return material guid with description by joining table MAKT with MARA:

@AbapCatalog.sqlViewName: 'PRODSHTEXT'
@VDM.viewType: #BASIC
@AccessControl.authorizationCheck: #NOT_REQUIRED
@ClientHandling.algorithm: #SESSION_VARIABLE
@EndUserText.label: 'Product Description'
define view ProductShortTextas select from maktinner join   mara on makt.matnr = mara.matnr
{key mara.scm_matid_guid16 as ProductGuid,key makt.spras            as Language,makt.maktx            as ProductName,makt.maktg            as ProductNameLarge

Create a new class and you do not need to create any method within this class.

Activate the class and perform unit test, you should see the information message that unit test is successfully executed.

Now let’s see how the whole scenario works.

Step1 – Test environment creation

This is done in CLASS_SETUP method:
cl_cds_test_environment=>create( i_for_entity =’PRODUCTSHORTTEXT’ ).

From the CASE-WHEN statement below we can know that the CDS test framework still supports various Database other than HANA.

Step2 – CDS view source code parse

The framework should know which database tables are used in the CDS view under test, since the mock data is inserted to database table level, not CDS view level.

The source code parse is done via a Visitor pattern and result stored in r_result, which contains two table, MARA and MAKT of course.

If you would like to know how this Visitor pattern works in detail, please refer to my blog Visitor pattern used in CDS View Test double framework.

Step3 – Created transient tables based on parsed database table

Since the test double framework knows from step2 that MARA and MAKT are involved in the CDS view under test, so now it is able to create transient tables based on both. The created tables are dummy, which is used to hold test data inserted in the unit test, and those dummy tables will be destroyed when the test environment is destroyed, I would like to call them as shadow table.

Step4 – unit test developers insert test data to shadow table

Unit test developers now prepare test data, wrap it by calling cl_cds_test_data=>create, and insert the wrapped test data into shadow table via API insert provided by test double framework.

In next step when the CDS view under test is queried in unit test code, the inserted data prepared in this step will be serving as response.

Step5 – OPEN SQL redirected to shadow table

When the CDS view is queried, the read operation will be actually redirected to shadow table created in step 3.

And how CDS test double framework knows which shadow table should be redirected for MARA and which for MAKT?
Actually in step3, when shadow table are created, the relationship between original table and created shadow table are maintained in an internal table:

Based on this metadata, the real redirection is switched on by a Kernel implementation:

Update on 2017-04-25 15:39PM

I remove the explanation on how the kernel module mentioned above is implemented as my ABAP colleague tells me it should not be published to the public.


SAP CDS view 单元测试框架 Test Double 介绍相关推荐

  1. SAP CDS view权限控制实现原理介绍

    Part1 – how to test odata service generated by CDS view Part2 – what objects are automatically gener ...

  2. Visitor(访问者)模式在SAP CDS view测试框架中的灵活运用

    CDS view test double framework visitor pattern

  3. SAP CDS view(Core Data Service)自学的一些材料和方法

    Self study和incident handling的不同之处 (1) incident handling有时间压力,遇到自己思路卡住求助同事无可厚非.而Self study没有太大的时间压力,要 ...

  4. 开源C++单元测试框架Google Test介绍

    开源C++单元测试框架Google Test介绍 Google Test Google test是针对c/c++的开源测试项目.采用的协议是BSD license,有很多著名的开源项目采用了它,包括C ...

  5. SAP CDS view性能调优的一些准则和例子

    SAP CDS view优化的guideline: 一个很简单的SELECT CDS view的open sql: 它的execution plan都会非常复杂: 我们就只展开上面execution ...

  6. Android单元测试框架Robolectric3.0介绍(一)

    Android单元测试框架Robolectric3.0介绍(一) 作者 geniusmart 关注 2016.01.21 00:37* 字数 1550 阅读 18265评论 55喜欢 124赞赏 2 ...

  7. 如何基于 SAP CDS view 生成 object page

    通过之前的文章如何在 SAP BTP 上通过 CDS view 快速创建 Fiori Elements 应用,我们已经创建了一个 CDS view,并基于该 CDS view,创建了一个 Fiori ...

  8. SAP CDS view源代码行数统计工具

    Part1 – how to test odata service generated by CDS view Part2 – what objects are automatically gener ...

  9. SAP CDS view自学教程之十:SAP CDS view扩展性(Extensibility)实现原理

    目录 Part1 – how to test odata service generated by CDS view Part2 – what objects are automatically ge ...


  1. Oracle 工程师离职并回踩:MySQL 糟糕透顶,强烈推荐 PostgreSQL
  2. NSString取子串
  3. qq android2.0,取代QQ?腾讯TIM安卓2.0发布:10GB云盘免费用
  4. CCIE-LAB-第七篇-IPV6 EIRGP+Passive
  5. plsql数据库异常---plsql 登录后,提示数据库字符集(AL32UTF8)和客户端字符集(ZHS16GBK)不一致 .
  6. 第六章:如何在SpringBoot项目中使用拦截器
  7. c++和java哪个难_为什么说C语言比Java难?
  8. vue项目做本地代理
  9. Tapestry5之国际化
  10. NotifyIcon用法
  11. 2021年危险化学品经营单位安全管理人员考试及危险化学品经营单位安全管理人员考试资料
  12. 常见的各种人提出的理论
  13. 基于Multisim的简易数字钟
  14. Android 获取应用「唯一标识符」——DeviceID「兼容android 10(Q)」
  15. 加工制造业经销商渠道管理系统:共享上下游信息,加速交易效率
  16. 【论文解读 WWW 2019 | MVAE】Multimodal Variational Autoencoder for Fake News Detection
  17. 网工容易混淆的三种网线类型:直连线、交叉线和反转线
  18. 纯CSS无hacks的跨游览器多列布局
  19. 什么是超弦理论?它与姓名有什么关系?
  20. 在Win7上安装AutoCAD2007碰到的问题及其解决办法


  1. PHP Module
  2. LUA实现单词替换功能
  3. iOS 字典与字符串之间的互转
  4. Cocos2d-x编程中CCRemoveSelf与CCCallFunc系列函数不能一起使用
  5. Pxe+Kickstart批量网络安装操作系统
  6. Rsync的使用方法
  7. 基环树一些有趣的事情
  8. ASP.Net Telerik RadGrid动态生成表头
  9. MFC 网络编程小结
  10. SAP屏幕设计器专题:编写控件代码(三)