如何测试涉及开始新任务的流量?
目前,我正在使用带有接口的数据访问对象模式来替换数据库访问使用内存数据以进行单元测试。例如方法find_product_by_id
。 zcl_xyz_user_mem
用于单元测试/集成测试,生产_DB
。
现在,我需要在背景中做一些事情的问题(启动新任务
)。在这里,我无法使用内存数据传递_mem
。我也迫不及待地想在测试案例中完成ASYNC。
产品用例就是这样:
- HTTP调用触发方法A调用B,C,D
- D启动新的task1
- Task1做事并可选。
方法 任务和task1没有内存对象。
问题:是否有任何方法可以用_mem
调用方法A,将该_MEM
进入新任务,等待任务完成并在_MEM中验证结果
(我可以看到Task1代码和方法E做对了)吗?
I'm currently using the Data Access Object pattern with interfaces to replace the database access with in-memory data for unit tests. E.g. method find_product_by_id
. the ZCL_XYZ_USER_MEM
is used for unit tests / integration tests, the _DB
for production.
Now I've the problem that I need to do some stuff in background (STARTING NEW TASK
). Here I cannot pass my _MEM
with the in memory data. I also cannot wait for async to finish in the test case.
The prod use case is like this:
- HTTP Call triggers methods A which calls B,C,D
- Method D starts new task1
- task1 does stuff and optionally calls method E.
So in the prod flow, method D does not use ON END OF TASK
, and task1 does not have the in-memory object.
Question: Is there any way to call method A with _MEM
, get that _MEM
into the new task, wait for the task to finish and verify the result in _MEM
(so I can see that the task1 code and method E did the right thing)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不再是单位测试。这正在测试独立单元A,B,C,D,TESK1和E之间的整合。因此,它是一个集成测试。这意味着像ABAP单元这样的单元测试框架不是正确的工具。
当然,您可以(并且应该)使用ABAP单元为方法A,B,C,D,Task1和E创建单独的测试。这些测试应孤立执行这些单元。这意味着测试直接调用它们,并使用模拟对象拦截,确认和验证数据库操作以及它们应该彼此进行的方法或SAP标准功能。
但是,在测试这些方法之间的相互作用时,您应该使用集成测试框架。像
This is not a unit test anymore. This is testing the integration between the independent units A, B, C, D, task1 and E. So it's an integration test. That means that a unit testing framework like ABAP Unit isn't the right tool for it.
Of course you can (and should) use ABAP Unit to create separate tests for the methods A, B, C, D, task1 and E. Those tests should execute those units in isolation. Which means the tests call them directly, and use mock objects to intercept, confirm and validate the database operations and the method calls they are supposed to do to each other or to SAP standard functionality.
But when it comes to testing the interaction between those methods, then you should use an integration testing framework. Like eCATT, for example, which can be used to test whole business processes and their results using GUI scripting. This test operates on the GUI layer, so it's usually not possible to keep them side-effect free. They are going to create some "real" operations on the system, which leave their traces. When those operations are client-specific, then one option is to start each run of the test suit with a client copy, so you are operating on a client with a pristine set of test data. Another option is to add a "cleanup" stage to each test which undos the operations performed by the test before and bring the test data into a state where the test can be repeated.