使用SAP CRM Mock framework进行单元测试 CRMSAPSAP云平台SAP Cloud PlatformSAP成都研究院
There is an interface IF_CRM_PRODUCT_PROXY in CRM which declares almost all function modules from function group COM_PRODUCT_API for product master access.
This interface is implemented by three classes below.
CL_CRM_PRODUCT_PROXY will delegate the call to MOCK_PROXY( for unit test ) or REAL_PROXY( for productive use ) according to different mode in which the code is running. As an application developer, we do not directly call CL_CRM_PRODUCT_PROXY in our application code, but use another wrapper class CL_CRM_PRODUCT_API instead. For example, I would like to get the product guid for product with id “I042416”, I use the following source code:
In productive use scenario, the callstack could be found below: our test report calls CL_CRM_PRODUCT_API, which calls CL_CRM_PRODUCT_PROXY, which then calls the productive implementation – CL_CRM_PRODUCT_REAL_PROXY. Inside the real proxy, function module COM_PRODUCT_GUID_GET is called.
How to use CRM mock framework to make fake product guid is returned
Suppose in my unit test code, I would like a fake guid “AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA” is returned by the same source code. 1. Just add the following source code to let CL_CRM_PRODUCT_PROXY know that currently the code is running under mock mode.
cl_factory_proxy=>set_source( iv_source = 'MOCK'
iv_xml_master_data_file = '\\TSHomeServer\TSHome$\i042416\Desktop\test.xml'
iv_read_from_mime = abap_false ).
This code would probably be inserted into the class_setup of your unit test code.
- paste the following source code into your test.xml:
<Mock XMLCompressVersion="2">
<XMLRC_Object ObjectName="CL_CRM_PRODUCT_API" Component="COM_PRODUCT_GUID_GET" input="8B70F13430313231340300">
<EV_PRODUCT_GUID>qqqqqqqqqqqqqqqqqqqqqg==</EV_PRODUCT_GUID></XMLRC_Object></Mock>
- Where does input 8B70F13430313231340300 in xml come from? Set a breakpoint on function module PROXY_CONVERT_TO_STRING,
and you can know this value is calculated based on the zip operation of the concatenated value based on all input parameter values ( in my example, it is CDI042416 )
- Where does qqqqqqqqqqqqqqqqqqqqqg== for IV_PRODUCT_GUID in xml come from?
Execute function module SSFC_BASE64_ENCODE in test mode, paste the fake guid AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA and execute it, then you get base64 encoded value. Paste the value into xml file.
- Now execute the test report once again. From callstack you can see that the MOCK_PROXY is called, the faked guid is fetched from XML and returned:
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
上一篇: 如何用SAP CRM中间件从ERP下载material division到CRM CRMSAPSAP云平台SAP Cloud PlatformSAP成都研究院
下一篇: 黑莓复兴艰难:季度亏损8400万美元
推荐阅读
-
使用SAP CRM中间件XIF(External Interface)一步步创建服务订单 SAP成都研究院SAP Cloud PlatformSAP云平台SAPABAP
-
Product settype在CRM WebClient UI架构中的地位 SAPCRMSAP成都研究院SAP Cloud PlatformSAP云平台
-
Account group in ERP and its mapping relationship with CRM partner group ERPCRMSAP成都研究院SAP Cloud PlatformSAP云平台
-
SAP CRM中间件下载时数据库表CRMATAB为空的处理方法 SAP成都研究院SAP Cloud PlatformSAP云平台CRM中间件
-
SAP CRM里产品主数据的文本模型设计 SAP成都研究院SAP Cloud PlatformSAP云平台SAPFiori
-
如何关闭SAP CRM中间件的delta download方式 CRM中间件SAP成都研究院SAP Cloud PlatformSAP云平台
-
How to test Delta download in CRM Side CRM中间件SAP成都研究院SAP Cloud PlatformSAP云平台
-
How to download sales BOM from ERP to CRM SAP成都研究院SAP Cloud PlatformSAP云平台SAPABAP
-
使用SAP CRM中间件从ERP下载Customer的错误消息 SAPSAP云平台SAP Cloud PlatformSAP成都研究院Cloud
-
SAP CRM Fiori应用冗余round trip的原因分析 SAP成都研究院SAP Cloud PlatformSAP云平台CRMOData