“Smells in Test that indicate Design problems”
(http://blogs.agilefaqs.com/2009/02/01/smells-in-test-that-indicate-design-problems/)。
原文如下:
Following are some of the conclusions from the discussion:
- Too many test cases per method: may indicate that the method is doing too much. We discussed the fact that complex business logic algorithms, with lots of special case, often appear to be atomic and indivisible; and thus only testable as a unit. But there is often a way to break them down into smaller pieces. Also sometimes one needs to think if all those special cases are really required now or we are speculating?
- Poorly factored edge cases: this is the case where there are many variations of input tested, when a few carefully-chosen edge cases would suffice. We discussed how this sometimes emerges when the algorithm under test has too many special cases, and the same result could be arrived at with a more general algorithm.
- Increasing access privilege of members (methods or instance variables) to protected or public only for testing purpose: sometimes indicates that you are coupling your tests too much with the code. Sometimes it indicates that may be the private thing has enough behavior that it needs to be tested. In that case may be you should consider pulling it out as a separate object
- Too much setup/teardown: indicates strong coupling in the class under test.
- Mocks returning mocks: indicate that the method under test has too many collaborators.
- Poorly-named tests: sometimes means that the naming and/or design of the classes under test isn’t sufficiently thought-out.
- Lots of Duplication in tests: sometimes indicate that the production code should be providing a way to avoid some of that duplication.
- Extensive Inheritance in test fixtures: indicate that your design might heavily rely on inheritance instead of composition.
- Double dots in the test code: indicates that the code violates the law of Demeter. In some cases it might be better to hide the delegate.
- Changing one thing breaks many tests: may just indicate bad factoring of tests, but can also indicate excess dependencies in the code.
- Dynamic stubs (stubs with conditional behavior): indicates lack of control over the collaborator that is being stubbed out. This sometimes indicate the behavior is not distributed well amongst the classes.
- Too many dependencies that have to be included in the test context: indicates tight coupling in the design
- Random test failures when running them in parallel: indicates that the code is not thread safe and has side-effects that are not factored correctly.
- Tests run slowly: indicates that your unit tests might be hitting external systems like network, database or filesystem. This usually indicates that the class under test might have multiple responsibility. One should be able to stub out external dependencies.
- Temporal coupling - tests break when run in a different order: may just be a test smell; may be coupling in the code under test.
分享到:
相关推荐
- **测试效果**:单元测试不仅能够发现代码中的浅层问题,还能揭示深层的设计缺陷,确保代码实现了预期的功能,并未执行不应有的操作。 - **成本控制**:早期发现并解决问题的成本远低于后期修复的成本。通过在单元...
单元测试是软件开发过程中的重要环节,它是一种针对程序模块进行的独立测试,旨在验证代码的各个小部分,如函数、方法或类,能够按照预期正常工作。在本章中,我们将深入探讨单元测试的概念、重要性以及如何进行有效...
总而言之,单元测试是软件工程中不可或缺的一环,它有助于早期发现问题、提升软件质量、降低修复成本,并加速系统集成过程。高质量的单元测试需要详尽的设计文档支持,并通过合理的测试策略、良好的测试管理以及测试...
单元测试的重要性体现在多个方面: - **提高代码质量**:通过单元测试可以及早发现并修复错误,确保代码质量。 - **简化调试过程**:定位错误变得更加容易,减少调试时间。 - **增强重构信心**:重构时可以快速验证...
在本文中,我们将讨论单元测试的基础知识,包括单元测试的重要性、测试设计的心得、单元测试的目的和进行方法等。 单元测试的重要性 ---------------- 单元测试是软件测试中的一种基本测试方法,它能够帮助开发者...
在单元测试中,测试用例的设计主要是为了覆盖程序的逻辑和路径。语句覆盖、判定覆盖、条件覆盖、判定——条件覆盖、条件组合测试、路径测试等都是常用的测试方法。 在设计测试用例时,需要考虑到软件的每个单元的...
单元测试的重要性体现在以下几个方面: * 早期发现错误:单元测试可以帮助开发者早期发现错误,从而减少错误的影响。 * 提高软件质量:单元测试可以帮助提高软件的质量和可靠性。 * 降低成本:单元测试可以帮助降低...
单元测试的必要性还体现在优秀的开发和测试团队的早期介入上。统计表明,在开发过程的不同阶段发现缺陷的成本差别巨大。越早介入,发现缺陷的成本就越低,而且更容易修正。因此,开发团队在设计和编码阶段就应进行...
- 静态测试:不运行软件,通过审查代码、文档或设计来查找问题,如代码审查、静态分析等。 - 动态测试:执行软件来检测错误,包括黑盒测试和白盒测试。 - 黑盒测试:关注软件的功能,不关心内部结构,模拟用户操作...
1. **早期发现问题**:在开发过程中进行单元测试,可以及时发现代码中的错误和缺陷,避免这些问题在后续的集成测试或系统测试中暴露出来,减少修复成本。 2. **提高代码质量**:编写单元测试迫使开发者考虑各种边界...
《单元测试之道》一书由Andy Hunt、Dave Thomas与Matt Hargett共同撰写,通过深入浅出的方式,向读者展示了如何在C#中运用NUnit框架进行有效的单元测试。本书不仅是一本技术指南,更是对程序员技能提升的一次深度...
在这个“Struts2之Servlet API及单元测试初识案例struts005”中,我们将探讨Struts2如何与Servlet API结合使用,以及如何进行单元测试。 Servlet API是Java EE平台的核心部分,用于构建动态Web应用程序。Struts2...
在软件开发的过程中,单元测试是保证软件质量的重要手段之一。随着微服务架构和持续集成(CI)的流行,单元测试变得更加重要。TDD(测试驱动开发)强调了单元测试的重要性,使其成为了开发流程的核心部分。C++作为...
单元测试是软件开发过程中的重要环节,它允许程序员对代码的各个模块进行独立验证,确保它们按照预期工作。一个简单的单元测试框架可以帮助开发者快速、高效地编写和执行这些测试,从而提升代码质量并减少错误。下面...
在“软件单元测试(2005-10).ppt”和“软件集成测试(2005-10).ppt”中,可能会详细介绍如何设计和执行这些测试,包括测试框架的选择、测试驱动开发(TDD)和行为驱动开发(BDD)的概念,以及如何编写有效且全面的测试...
以下是对单元测试中涉及的知识点的详细解释: 1. 距离矢量路由协议:这类协议如RIP(Routing Information Protocol)或IGRP,依赖于相邻路由器发送的路由更新来维护其路由表。路由器D选项正确,它依靠邻居发送的...
【冀教版七年级语文上册第一单元测试题及答案精选.doc】是一个针对七年级学生设计的语文单元测试文档,旨在检验学生对于该单元知识点的掌握情况。文档内容包括诗词填空、文学常识、仿写句子以及文言文阅读理解等多...