SAP 函数CRM_ORDERADM_I_PROD_DETERM_OW的单元测试方法
For more detail about how product determination works in one order scenario, please refer to this blog: Product Alternative ID used in Opportunity Line item product determination.
As it is not possible to only create the test class for a given function module via ABAP unit test framework, but the test class has to be created on function group level:
For demonstration purpose I would not like to modify SAP standard function group, so I create a new local class as wrapper with a method name which is exactly equal to the function module name. As a result now I can just create local test class against this wrapper class by ABAP unit test wizard:
For determination failure case, it is easy to implement, just pass an non-existing ordered product as input parameter value for iv_ordered_product. If determination fails as expected, es_product_detail and cv_ordered_prod will remain initial.
For successful determination case, I expect that the standard product id ( gv_prod_id ) should be determined based on alternative ID ( gv_altid ).
In my unit test, the alternative ID value contained in gv_altid and the product id contained in gv_prod_id are fake, neither of them point to a real product in the system. When I debug the product determination based on real product performed in WebUI, I found these two database tables are joined for determination.
As a result, I plan to create corresponding dummy entry in these two database tables in the SETUP method of test class:
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_16 = mv_fake_prod_guid.
ls_mock_alt_id = VALUE #( product_guid = mv_fake_prod_guid
upname = sy-uname
altvehno = gv_altid ).
INSERT isam_o_veh_ids FROM ls_mock_alt_id.
DATA(prod) = VALUE comm_product( product_guid = mv_fake_prod_guid
product_id = gv_prod_id
product_type = '01' upname = sy-uname ).
INSERT comm_product FROM prod.
COMMIT WORK AND WAIT.
And remove them in TEARDOWN:
METHOD teardown.
DELETE FROM isam_o_veh_ids WHERE product_guid = mv_fake_prod_guid.
DELETE FROM comm_product WHERE product_guid = mv_fake_prod_guid.
COMMIT WORK AND WAIT.
ENDMETHOD.
In the meantime, the determination function module needs a guid for one order header object ORDERADM_H. When the function module is executed, the header data will be read from buffer. In my unit test, in order to ensure that the header read from buffer succeed, I have to first insert the buffer of dummy object header via the following code in SETUP method:
DATA: ls_mock_header TYPE crmt_orderadm_h_wrk,
ls_mock_alt_id TYPE isam_o_veh_ids,
lt_link TYPE crmt_link_comt,
ls_link LIKE LINE OF lt_link.
CREATE OBJECT f_cut.
CALL FUNCTION 'GUID_CREATE'
IMPORTING
ev_guid_16 = mv_header.
ls_mock_header-guid = mv_header.
ls_mock_header-process_type = gv_oppt_proc_type.
CALL FUNCTION 'CRM_ORDERADM_H_PUT_OB'
EXPORTING
is_orderadm_h_wrk = ls_mock_header.
The unit test could successfully be executed and all tests pass:
However, when looking back about the unit test implementation, I find the test has dependency on the transaction type which must exist in current system and has been configured with Alternative ID correctly.
Suppose my unit test code is transported to a testing system where type “ZJER” does not exist, the unit test will fail there.
As a result, the improvement would be:
(1) Change the constant value of process type from “ZJER” to a type which does not exist in any system, for example “ABCD”:
(2) Append the following source code to the end part of SETUP method, to create a temporary transaction type for unit test purpose:
(3) Remove the temporary transaction type in TEARDOWN method:
As displayed above, I have two test methods DETERMINE_OK and DETERMINE_FAIL to test these two boundary conditions.
要获取更多Jerry的原创文章,请关注公众号"汪子熙":
相关文章
- SAP UI5 XML 视图在实例化时就已经确定了 BindingSyntax 的实现版本了
- 通过 FileUploader 的初始化,了解 SAP UI5 应用的 StaticArea 初始化逻辑
- SAP UI5 应用开发教程之六十九 - 如何从 SAP UI5 Not Found 页面跳转回到正常的应用页面试读版
- SAP UI5 的前世今生
- SAP UI5 里如何让每次视图显示时都执行某方法
- SAP UI5 应用 filter 功能不能正常工作时的单步调试方法
- SAP UI5 Custom Cordova plugin的调试方法
- SAP UI5 local sandbox bootstrap的执行细节
- SAP UI5 js file will be executed immediately after downloaded successfully
- 如何给 SAP ABAP ALV 报表的修改功能添加自定义校验逻辑试读版
- 如何在 SAP ABAP 系统中使用 Adobe Form 试读版
- SAP S/4HANA生产订单的BAdI增强点之Initialize方法
- SAP CRM One order里user status和system status的mapping逻辑
- SAP Commerce Cloud 里 OAuth2 Client 的两种配置方法
- SAP 电商云登录界面如何增添新的字段
- 关于 SAP Spartacus 服务器端渲染 SSR 无法使用窗口宽度以进行自适应设计的问题
- SAP C4C Opportunity和SAP ERP Sales流程的集成
- SAP CRM WebClient UI控制器方法DETACH_STATIC_OVW_VIEWS的作用
- SAP Cloud SDK for JavaScript 的搭建和使用方法介绍
- 使用 SAP WebIDE 创建 SAP Fiori Elements 应用
- SAP Gateway Foundation Client Proxy 的使用方法
- SAP ABAP OData 服务 Data Provider Class 的 GET_ENTITYSET 方法实现指南试读版
- SAP 电商云 Spartacus Checkout 端到端测试