SAP 函数CRM_ORDERADM_I_PROD_DETERM_OW的单元测试方法-阿里云开发者社区

开发者社区> 开发者小助手-bz4> 正文

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.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.

版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。

相关文章
C++ 操作DLL的函数 Loadlibrary GetProcAddress FreeLibrary
C++ 操作DLL的函数 Loadlibrary GetProcAddress FreeLibrary
47 0
钉钉机器人调用函数计算实现serverless web服务:传统门禁的简单改造,懒惰癌的福音
本文通过钉钉机器人调用函数计算实现的serverless web服务,打通物联网平台,和树莓派实时通讯。实现了将原有传统的磁吸门禁,改造成可以由钉钉来控制开门的简单应用。
2236 0
阿里云服务器怎么设置密码?怎么停机?怎么重启服务器?
如果在创建实例时没有设置密码,或者密码丢失,您可以在控制台上重新设置实例的登录密码。本文仅描述如何在 ECS 管理控制台上修改实例登录密码。
8662 0
阿里云服务器端口号设置
阿里云服务器初级使用者可能面临的问题之一. 使用tomcat或者其他服务器软件设置端口号后,比如 一些不是默认的, mysql的 3306, mssql的1433,有时候打不开网页, 原因是没有在ecs安全组去设置这个端口号. 解决: 点击ecs下网络和安全下的安全组 在弹出的安全组中,如果没有就新建安全组,然后点击配置规则 最后如上图点击添加...或快速创建.   have fun!  将编程看作是一门艺术,而不单单是个技术。
10493 0
C语言程序-打豆豆(函数版)
【项目】 设计一个程序,能重复地在显示下面的信息: * 1. 吃饭 * 2. 睡觉 * 3. 打豆豆 * 0. 退出 * 请选择(0-3): 根据用户输入的选项,输出一句提示性的话语(将来会对应实现某个功能)。输入0,则退出。 要求将各功能定义专门的函数。 参考解答: #include <stdio.h> #define EAT '1
1093 0
阿里云ECS云服务器初始化设置教程方法
阿里云ECS云服务器初始化是指将云服务器系统恢复到最初状态的过程,阿里云的服务器初始化是通过更换系统盘来实现的,是免费的,阿里云百科网分享服务器初始化教程: 服务器初始化教程方法 本文的服务器初始化是指将ECS云服务器系统恢复到最初状态,服务器中的数据也会被清空,所以初始化之前一定要先备份好。
11438 0
SQL Server DATEADD() 函数
本文转载自:点击打开链接 SQL Server DATEADD() 函数 DATEADD(datepart,number,date)date 参数是合法的日期表达式。number 是您希望添加的间隔数;对于未来的时间,此数是正数,对于过去的时间,此数是负数。datepart 参数可以是下列的值: 具体实例:
863 0
2315
文章
0
问答
来源圈子
更多
+ 订阅
文章排行榜
最热
最新
相关电子书
更多
《2021云上架构与运维峰会演讲合集》
立即下载
《零基础CSS入门教程》
立即下载
《零基础HTML入门教程》
立即下载