SAP 函数CRM_ORDERADM_I_PROD_DETERM_OW的单元测试方法

简介: 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:


image.png

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:


image.png

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.



image.png

image.pngFor successful determination case, I expect that the standard product id ( gv_prod_id ) should be determined based on alternative ID ( gv_altid ).


image.png

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.



image.png

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:

image.pngHowever, 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.



image.png

image.png

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”:


image.png

(2) Append the following source code to the end part of SETUP method, to create a temporary transaction type for unit test purpose:image.png(3) Remove the temporary transaction type in TEARDOWN method:image.pngAs displayed above, I have two test methods DETERMINE_OK and DETERMINE_FAIL to test these two boundary conditions.

相关文章
|
20天前
|
人工智能 搜索推荐 Serverless
使用金庸的著作,来测试阿里通义千问最新开放的长文档处理功能
使用金庸的著作,来测试阿里通义千问最新开放的长文档处理功能
45 7
使用金庸的著作,来测试阿里通义千问最新开放的长文档处理功能
|
1月前
|
API
在阿里云RPA中,你可以使用"SetForegroundWindow"函数来将SAP控件置顶
【2月更文挑战第28天】 在阿里云RPA中,你可以使用"SetForegroundWindow"函数来将SAP控件置顶
20 1
|
1月前
|
Java Spring
使用JDBCTemplate实现与Spring结合,方法公用 ——测试(EmpDaoImplTest)
使用JDBCTemplate实现与Spring结合,方法公用 ——测试(EmpDaoImplTest)
8 0
|
16天前
|
存储
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
使用 ABAP 代码打印出 SAP CRM 系统里所有维护了 Sales Area 的 business partner id
19 0
|
15天前
|
自然语言处理 测试技术 持续交付
现代软件测试方法与挑战
传统软件测试方法在当前快速发展的软件开发环境下面临着诸多挑战,因此,现代软件测试方法的探索与应用显得尤为重要。本文将介绍几种现代软件测试方法,并探讨其在应对软件开发挑战方面的作用。
10 0
|
17天前
|
安全 测试技术
深入理解白盒测试:方法、工具与实践
【4月更文挑战第7天】 在软件开发的质量控制过程中,白盒测试是确保代码逻辑正确性的关键步骤。不同于黑盒测试关注于功能和系统的外部行为,白盒测试深入到程序内部,检验程序结构和内部逻辑的正确性。本文将探讨白盒测试的核心技术,包括控制流测试、数据流测试以及静态分析等方法,同时介绍当前流行的白盒测试工具,并讨论如何在实际项目中有效实施白盒测试。文章的目标是为软件测试工程师提供一份综合性指南,帮助他们更好地理解和应用白盒测试技术。
|
20天前
|
数据库
SAP CRM产品主数据无法根据产品描述字段进行搜索的原因
SAP CRM产品主数据无法根据产品描述字段进行搜索的原因
16 5
|
20天前
|
Web App开发 开发者 存储
介绍一个 webp 格式转 png 格式的软件:XNConvert
介绍一个 webp 格式转 png 格式的软件:XNConvert
24 6
介绍一个 webp 格式转 png 格式的软件:XNConvert
|
20天前
什么是 SAP ABAP 里的 Subscreen
什么是 SAP ABAP 里的 Subscreen
15 1
什么是 SAP ABAP 里的 Subscreen
|
29天前
|
传感器 监控 算法
【软件设计师备考 专题 】模块测试的方法和实践
【软件设计师备考 专题 】模块测试的方法和实践
71 0