你在写单元测试时最常犯的错误是什么?[英] What is the most common mistake you make while writing unit tests?

本文是小编为大家收集整理的关于你在写单元测试时最常犯的错误是什么?的处理/解决方法,可以参考本文帮助大家快速定位并解决问题,中文翻译不准确的可切换到English标签页查看源文。

问题描述

在编写单元测试时,您犯了什么最常见的错误?耦合?缺乏凝聚力?尝试一次测试过多的功能?测试功能不足?

如果您有一个错误的示例,请发布一些示例代码

推荐答案

根本不写它们.

其他推荐答案

在一次测试中测试过多.我的单位测试通常不将自己局限于正在测试的方法中来承担更多集成测试的特征.

其他推荐答案

测试是存在的代码,而不是应该存在的代码.

我倾向于测试编写单元测试时存在的代码.也就是说,我将编写一系列测试,这些测试具有极高的覆盖范围并测试了存在的大多数代码,但错过了代码未涵盖的基本错误条件.

本文地址:https://www.itbaoku.cn/post/627401.html

问题描述

What is the one most common mistake you make while writing unit tests? Coupling? Lack of cohesion? Try to test too much functionality at once? Not testing enough functionality?

Post some example code if you have an example of that mistake

推荐答案

Not writing them at all.

其他推荐答案

Testing too much in one test. My unit tests often take on more of the character of integration tests by not confining themselves to the method under test.

其他推荐答案

Testing code that is present, rather than code that should be present.

I tend to test code that is present when writing unit tests. That is, I'll write a series of tests that have exceptionally high coverage and test the majority of the code that's present, but misses out on basic error conditions not covered by the code.