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:
@AbapCatalog.sqlViewName: 'PRODSHTEXT'@VDM.viewType: #BASIC@AccessControl.authorizationCheck: #NOT_REQUIRED@ClientHandling.algorithm: #SESSION_VARIABLE@EndUserText.label: 'Product Description'define view ProductShortText
as select from makt
inner 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.
要獲取更多Jerry的原創文章,請關注公眾號"汪子熙":
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/24475491/viewspace-2714424/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- SAP ABAP CDS view 檢視的 Replacement 技術介紹View
- SAP CDS view自學教程之一:如何測試基於SAP CDS view自動生成的OData服務View
- Go 單元測試基本介紹Go
- SAP S/4HANA CDS View的訪問控制實現:DCL介紹View
- 一文掌握開源單元測試框架Google Test框架Go
- SAP CDS view自學教程之十:SAP CDS view擴充套件性(Extensibility)實現原理View套件
- vue單元測試vue test utils使用初探Vue
- ABAP和Java的單元測試Unit TestJava
- 單元測試框架 mockito框架Mockito
- JavaScript單元測試框架JavaScript框架
- Google 單元測試框架Go框架
- 如何寫好測試用例以及go單元測試工具testify簡單介紹Go
- T框架介紹(自動化測試框架)框架
- SAP ABAP CDS view Association 引入的緣由View
- 如何基於 SAP CDS view 生成 object pageViewObject
- 使用SAP CRM mock框架進行單元測試的設計Mock框架
- 前端單元測試框架梳理前端框架
- 單元測試利器Mockito框架Mockito框架
- SAP CDS view自學教程之二:當SAP CDS view被啟用時,背後發生了什麼View
- 簡單介紹Angular單元測試之事件觸發的實現Angular事件
- 簡單介紹.Net效能測試框架Crank的使用方法框架
- Django筆記三十六之單元測試彙總介紹Django筆記
- Python自動化測試框架介紹Python框架
- 如何使用 SAP CDS view 中的 currency conversion 功能View
- jest對react單元測試框架React框架
- Netty 框架學習 —— 單元測試Netty框架
- 單元測試模擬框架Mockito框架Mockito
- 四種ABAP單元測試隔離(test isolation)技術
- 什麼是SAP CDS重定向檢視(Redirect View)?View
- 在 Excel 內使用 ODBC 消費 SAP ABAP CDS viewExcelView
- PHP單元測試框架PHPUnit的使用PHP框架
- SAP Fiori Elements 公開課第一單元概要介紹
- 測試 之Java單元測試、Android單元測試JavaAndroid
- SAP UI5 初學者教程之二十七 - SAP UI5 應用的單元測試工具 QUnit 介紹試讀版UI
- 『居善地』介面測試 — 12、Moco框架介紹框架
- SAP ABAP CDS view 裡 INNER JOIN 和 Association 的區別View
- 使用CDS view開發SAP Marketing contact的facet追溯工具View
- Python單元測試框架pytest常用測試報告型別Python框架測試報告型別