如何在类中测试业务逻辑(How to test business logic in a class)

编程入门 行业动态 更新时间:2024-10-26 17:27:18
如何在类中测试业务逻辑(How to test business logic in a class)

所以我有一个系统已被分解为接口和实现,以允许模拟等。这一切都很棒,我可以测试所有的功能。 因为一切都有输入和输出。

现在,我的业务逻辑基本上是一个将整个系统连接在一起并指定事物如何流动的类。 我如何确保在特定点采取行动等?

我该如何测试这个商务舱?

So I have a system that has been broken down into interfaces and implementations to allow mocking etc. That is all great and I can test all the functions. Because everything has an input and output.

Now, my business logic is basically a class that ties this entire system together and specifies how things flow. How can I ensure that actions were taken at a specific point etc?

How can I test this business class?

最满意答案

如果它绑定整个系统可能你不需要进行单元测试。 它接缝更多的集成测试。

无论如何,如果您需要检查从业务类调用正确的步骤序列,您可以模拟业务类中使用的其他类(使用Mockito之类的库)并仅验证调用序列。

如果您需要真实数据来测试它,这不是单元测试,而是集成测试。

If it ties the entire system probably you don't need to unit test it. It seams more an integration test.

Anyway if you need to check that the right sequence of steps is called from your business class you can mock the other classes used from your business class (using libraries like Mockito) and verify only the sequence of calls.

If you need real data to test it this is not a unit test, but an integration test.

更多推荐

本文发布于:2023-08-02 17:49:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1378348.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:类中   逻辑   业务   测试   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!