SAP CDS view 单元测试框架 Test Double 介绍-阿里云开发者社区

开发者社区> c位出道> 正文

SAP CDS view 单元测试框架 Test Double 介绍

简介: SAP CDS view 单元测试框架 Test Double 介绍
+关注继续查看

系列目录

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:

image.png

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

image.png

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

image.png

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.


image.png

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.


image.png

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.

image.png

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.


image.png

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.


image.png

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:

image.png

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

image.png

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.


版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
python unittest框架理解
整个平台的搭建使用的是python的unittest测试框架,这里简单介绍下unittest模块的简单应用。 unittest是python的标准测试库,相比于其他测试框架是python目前使用最广的测试框架。
1213 0
SAP CRM Fiori Simulation Pipeline 设计介绍
SAP CRM Fiori Simulation Pipeline 设计介绍
7 0
SAP CRM 和 SAP Cloud for Customer 的表格列项目宽度调整的原理介绍
SAP CRM 和 SAP Cloud for Customer 的表格列项目宽度调整的原理介绍
19 0
SAP S/4HANA Cloud 系统集成的一些场景介绍
SAP S/4HANA Cloud 系统集成的一些场景介绍
8 0
Jerry在2020 SAP全球技术大会的分享:SAP Spartacus技术介绍的文字版
Jerry在2020 SAP全球技术大会的分享:SAP Spartacus技术介绍的文字版
17 0
单元测试框架TestNg使用总结
工欲善其事,必先利其器 单元测试的重要性是不言而喻的。但如果没有好的单元测试工具,是无法激起开发人员的欲望。 Testng便是利器之一。TestNG是基于Annotation的测试框架的先驱,他拥有通过添加诸如灵活的装置、测试分类、参数测试和依赖方法等特性来克服JUnit3的一些不足之处。
786 0
SAP UI5 WebIDE里使用Mock数据的工作原理介绍
Created by Wang, Jerry, last modified on Feb 02, 2015
5 0
+关注
2316
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载