Skip to content

[Improvement] unit test suggestion #3700

@SunJiFengPlus

Description

@SunJiFengPlus

Describe the question

  1. Put multi unit test cases in one method
  2. Only verify whether the result is successful or fail, not verify the data after successful

What are the current deficiencies and the benefits of improvement

  1. Put one unit test case in one method, take unit test case as the minimum test unit. Otherwise, the assertion failure of the previous unit test case will cause the subsequent unit test case to not be executed. If you just want to classify unit test cases, you can use the internal classes of junit5 and @DisplayName.
  2. Focus on verifying data. Focus on verifying data. If you just verify the success or failure, it will be meaningless. It looks like blindly increasing coverage. Such unit test will tolerate errors.

Describe the question

  1. 将多单元测试用例放在一种方法中
  2. 只验证结果成功还是失败, 不验证成功后的数据

What are the current deficiencies and the benefits of improvement

  1. 将一个单元测试用例放在一个方法中, 以单元测试用例为最小单元. 否则前一个单元测试用例的断言失败会导致后面的单元测试用例不会被执行. 如果只是想对单元测试用例分类, 可以使用junit5 的内部类和@DisplayName.
  2. 侧重验证数据. 如果只是验证成功与否, 这样意义不大. 看起来像是盲目提高覆盖率. 这样的单元测试用会容忍错误.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions