首页 > 解决方案 > 我应该遵循每个类模式或用例模式一个测试类来编写测试用例

问题描述

我是编写 Junit 测试用例的学习者。我见过编写 Junit 案例模式,我们通常按每个类的名称单独为每个类创建测试类,并在其各自的类中为该类的每个方法编写测试用例,以便实现最大的代码覆盖率。

我在想什么如果我为我的功能制作测试用例,那将是更好的选择,因为将来任何数量的方法签名更改我都不必为那些修改过的方法或新创建的方法更改或再次创建不必要的测试用例。因为那一刻我会为我开发的功能提供某些测试用例。因此,我的测试用例对于特定功能运行良好,然后我可以确定在最少数量的测试用例代码中一切都很好。

通过保持这一点,我不必为每个类的每个方法编写测试用例。这是一个好方法吗?

标签: javajunitjunit4

解决方案


Well, test cases are written for a reason. Each and every methods have to be working properly as expected. If you only do test cases for the feature level, how do you find exactly where the error occurred and how confidently you can ship your code to next level? The better approach will be to do unit test cases for each class and do an integration test to make sure everything works good.


推荐阅读