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.


相关文章
|
5月前
|
SQL Android开发
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
创建 SAP ABAP CDS View 保存失败 - Dependencies DDL source - View Entity not written
|
5月前
|
SQL Oracle 关系型数据库
oracle11g SAP测试机归档日志暴增排查(二)
oracle11g SAP测试机归档日志暴增排查(二)
274 1
|
5月前
|
Oracle 关系型数据库 Shell
oracle11g SAP测试机归档日志暴增排查(一)
oracle11g SAP测试机归档日志暴增排查(一)
63 1
|
2月前
|
JavaScript 前端开发 测试技术
Vue.js开发者必看!Vue Test Utils携手端到端测试,打造无懈可击的应用体验,引领前端测试新风尚!
【8月更文挑战第30天】随着Vue.js的普及,构建可靠的Vue应用至关重要。测试不仅能确保应用质量,还能提升开发效率。Vue Test Utils作为官方测试库,方便进行单元测试,而结合端到端(E2E)测试,则能构建全面的测试体系,保障应用稳定性。本文将带你深入了解如何使用Vue Test Utils进行单元测试,通过具体示例展示如何测试组件行为;并通过Cypress进行E2E测试,确保整个应用流程的正确性。无论是单元测试还是E2E测试,都能显著提高Vue应用的质量,让你更加自信地交付高质量的应用。
45 0
|
2月前
|
Java 测试技术
Java SpringBoot Test 单元测试中包括多线程时,没跑完就结束了
Java SpringBoot Test 单元测试中包括多线程时,没跑完就结束了
24 0
|
3月前
|
Java 测试技术 程序员
测试气味Test Smells-整洁单元测试
摘要:本文讨论了代码中的“Code Smell”现象,即可能表明代码质量问题的模式。这些包括重复代码、过长函数、过大类、过长参数列表等。识别并重构Code Smell有助于提升代码质量和可维护性。在单元测试中,也有类似的“测试味道”问题,如无信息的测试名称、缺少arrange-act-assert结构、不恰当的变量名和重复使用以及杀虫剂效应。好的单元测试应有明确的命名、遵循arrange-act-assert模式、使用有意义的变量名,并避免重复测试同一情况,以提供有价值的错误信息。
|
4月前
|
Java
springboot Test 测试类中如何排除一个bean类
springboot Test 测试类中如何排除一个bean类
92 0
|
5月前
|
Web App开发 开发者 存储
介绍一个 webp 格式转 png 格式的软件:XNConvert
介绍一个 webp 格式转 png 格式的软件:XNConvert
介绍一个 webp 格式转 png 格式的软件:XNConvert
|
5月前
|
数据库 存储 BI
SAP ABAP CDS View 源代码存储的数据库表揭秘和其他相关数据库表介绍试读版
SAP ABAP CDS View 源代码存储的数据库表揭秘和其他相关数据库表介绍试读版
SAP ABAP CDS View 源代码存储的数据库表揭秘和其他相关数据库表介绍试读版
|
5月前
|
数据库
SAP S/4HANA 系统的底层基石 - 通过实际的例子,介绍 CDS View 入门级的概念试读版
SAP S/4HANA 系统的底层基石 - 通过实际的例子,介绍 CDS View 入门级的概念试读版
SAP S/4HANA 系统的底层基石 - 通过实际的例子,介绍 CDS View 入门级的概念试读版
下一篇
无影云桌面