`

在团队中进行单元测试/TDD的12条经验

 
阅读更多

12 Lessons I learned using unit tests/TDD

在团队中进行单元测试/TDD的12条经验

Introduction

Two years ago, I was working in a project where our goal was to write a web excel-like application to calculate products/services prices. The team was splitted in 3 pieces, the development team, the requirement team and the QA team. This project became so big and we didn’t use any types of automated tests (our QA team was doing manual tests) that the project spent more time being tested than being developed. Each little change, the project spent hours, hours and hours with the QA team. One day I went to a developer meeting and talked about my problem with others programmers. They suggested to me learn about unit tests, acceptance tests and TDD.

Learned Lessons

The list below is a lessons list that I learned while applying unit tests/TDD since 2011.

1. Don’t try to apply TDD for the first time or teach TDD to your team in a real project. It won’t work. First is necessary to know how TDD’s flow works. How to mock up objects, how to mock up the framework internals, how organize tests and so on, if your team is not ready, it will slow down the development and you will miss some deadlines.

2. Coding Dojo is a good way to teach TDD. We do coding dojo sessions. It’s the best way we found to teach TDD to new developers and to keep our skills up-to-date.

3. Try to convince your whole team before applying TDD. There isn’t nothing more frustrating than one or two developers ruining our test efforts, commenting code, trying to commit with failing tests and so on. I had bad experiences with non committed developers. Explain about the benefits, how tests keep our software bug-free, how we can refactor the code without worry about break the software and so on.

4. Write sufficient tests. Build a test suite is like to build a shield against bugs, the team should be able to fully trust in this shield when we are doing a refactoring or evolving the software. If this shield has gaps, we are increasing the risk to create unidentified bugs when we change the code. You don’t have to cover 100% of your code, it’s almost impossible and you will lose too much time but cover the majority of your code is perfectly achievable. A good rule is test everything that can possibly break.

5. Use a coverage tool. Coverage tools will report gaps in our test suite. With these tools, is easy to identify code that aren’t being tested. Most of these tools give to us a visual identification, coloring the lines that are being tested in blue/green and coloring in red the lines that are not being tested. If you are a .NET Programmer, the Visual Studio Ultimate comes with this feature or if you are a Java Programmer you can use the EclEmma.

 

6. Tests should be fast. Fast to run and fast to write. When we are building software we are always pursuing a deadline. Our tests have to help us to achieve this goal and not be a distraction or a delay.

If our tests take too much time to be written, the team will stop to write them when the deadlines become too tight.
If our tests take too much time to run, the team won’t run them everytime they change the code or they would decrease the team’s productivity.

7. Don’t comment or ignore failing tests. Once your team becomes comfortable with build failing due to 1 test, they will be comfortable with the build failing due to 2, 3, 4 tests and so on. At these times, the test suite feedback will be ignored and the tests won’t be helpful anymore.

8. Pair programming helps the team to adopt TDD. When we are trying TDD for the first time or when our deadline is tight, we will have the will to forget the tests and write only production code. Pair programming will prevent the team to cut corners and will keep it writing tests.

9. Keep your test code clean. Once, to speed our productivity, we decided that our test code shouldn’t be as clean as our production code. At first look, it was a good decision but software will change and tests will have to be changed too. We ended up with tests difficult to maintain and with larger estimates due the cost to maintain the tests.

10. Tests should have one and only one reason to fail. Be careful if your test has a lot of assertions. If functions and classes should have only one responsability, our tests should test only one concept. In this way, it will be easier to look at a failed test and figure out what is wrong.

11. Write unit tests will save debug time. A lot of time is spent debugging code, looking for bugs. Once you are writing unit tests, you will have a real-time feedback of each piece in your code, it will be easier to find bugs and consequently and it will reduce the time we spend debugging.

12. Keep pushing. Apply TDD is all about change our mindset. It’s difficult to start to write tests and is even more difficult to write tests BEFORE to write production code. It’s important to keep pushing and writing tests, one day, they will end up saving our lives. Also, once your team is fully comfortable with TDD, the productivity tend to increase.

 

分享到:
评论

相关推荐

    TDD团队中的测试人员

    测试驱动开发(TDD)是一种开发方式,它改变了传统软件开发的流程,即首先设计程序,再进行编码与测试工作。TDD采取了很小的增量式开发方式:首先编写一个测试,再...这样一来,我们就需要重新反思是否有必要在TDD团队中

    测试驱动开发的3项修炼-走出TDD丛林

    从TDD为什么实践起来非常困难等最根源的问题入手,循序渐进地介绍了构筑TDD的三项修炼,涉及到未雨绸缪的单元及自动化测试、结构化、敏捷以及平衡式的开发迁移、软件开发和重构设计以及大量的实践心得和经验总结归纳...

    android-tdd-bootstrap

    对于单元测试,我将使用可用的JUnit支持,对于平台测试,我将使用Espresso。 android-tdd-bootstrap ##目标: 将提供TDD引导Android项目 启用preL设备的材料设计(使用appcompat-v7) 我喜欢TDD,所以我想为...

    -Hands-on-Test-Driven-Development-with-Python:Packt发行的Python动手测试驱动开发

    接下来,您将了解单元测试和TDD中的一些最佳实践,并通过在Python中使用TDD实现单元测试来获得一些编程方面的实践经验。 在本课程结束时,您将能够每天应用单元测试和TDD的实践,从根本上提高代码质量,并帮助您和...

    swift-MockFive一个Mocking框架用于Swift单元测试

    在 TDD 开发中,需要先跑通测试然后再写具体实现,因此需要先伪造出实现类和函数来通过测试,这就是 Mock。如果你的团队使用 TDD 开发流程,这个框架会非常有用。

    软件测试应该注意的几大误解

    对测试的误解1."你只需要做单元测试——TDD测试已经足 软件测试应该注意的几大误解 软件测试 最近看了网络上所谓专家写的文章,发现了一些对TDD与QA部门的误解。本文将解释部分误区,并集中讨论QA团队要在敏捷的...

    wcci-columbus-2017-fall:9月25日至12月15日运行的全职Java全栈编码Bootcamp

    单元测试/ TDD(Junit)* 职业服务: 第三周 集合概述(*迭代器/迭代器) 清单 地图 继承与多态 封装形式 职业服务: 第四周 依赖注入/ Spring 测试双打(Mockito)* 例外情况 使用Gradle构建自动化* 职业服务...

    毕业设计源码java-columbus-2018-spring:哥伦布-2018-Spring

    单元测试/TDD (Junit)* 职业服务:周五爆头 第 3 周 集合概述 (*Iterables/Iterators) 列表 地图 继承与多态 封装 就业服务: 第 4 周 依赖注入/Spring 测试双打 (Mockito)* 例外 使用 Gradle* 构建自动化 就业服务...

    unittest-demo::blue_book: Node.js单元测试实例

    要在Nodejs中写单元测试的话,你需要知道用什么测试框架,怎么测试异步函数,怎么测试私有方法,怎么模拟测试环境,怎么测试依赖HTTP协议的web应用,需要了解TDD和BDD,还有需要提供测试的覆盖率。目录测试框架断言...

    毕业设计订餐系统源码-columbus-2018-summer:哥伦布-2018-夏季

    单元测试/TDD (Junit)* 就业服务: 集合概述 (*Iterables/Iterators) 列表 地图 就业服务: 在班上: 作业:复习 依赖注入/Spring 测试双打 (Mockito)* 继承与多态 封装 使用 Gradle* 构建自动化 就业服务: 春天 ...

    devoxx-tdd-puissance4

    根据 TDD 原则,您的类必须允许您通过功能团队在 Power4Test 类中定义的所有单元测试 - 这也是提供给您的。 如需更多详细信息,请参阅 Enonce.pdf 文件。 您将评估您的应用程序与这些规范的一致性(它必须通过所...

    create-react-app-redux-boilerplate:样板代码和安装说明,使用create-react-appReduxTravisCI为TDD流程创建步行框架

    它可以与TDD一起使用,并具有用于单元,集成和端到端测试的基本设置。 地位 CI服务 测验 现场演示 或者在Github Pages我的Storybook的。 科技栈 Create-react-app,其中包括:React,JSX,ES6,Webpack,Babel和...

    rex:Rails 中的 React 示例

    新前端的一个关键要求是向 JavaScript 添加单元测试,希望达到团队可以练习一些(尽管 DHH 宣布 TDD 已死)。 其他指南对要采取的方向提供了相当多的见解。 Oliver Lance 的文章特别有用。 但是,它没有解决测试...

    Projekt3-chess

    在项目中,每个参与者都应提供有关与TypeScript相关的以下问题的实践知识: 基本类型定义自己的类型折叠类型类型/类/接口接口的实现/继承/组成/实现访问修饰符通用类型单元测试和TDD 不要使用任何实现国际象棋引擎的...

    designing-cloud-native-microservices-on-aws

    在AWS上设计Cloud Native Microservices(通过DDD / EventStormingWorkshop) 来自的免费图片许可 ...单元测试环境中的TDD 生成单元测试代码框架 从代码框架实现领域模型 在端口适配器概念中设计每个微服

    tdd-exercises

    使用gulp gulp test (通过业力,摩卡,西农)运行单元测试。 在开发模式下运行 使用gulp serve-dev运行项目 在浏览器中将其打开,并使用所有文件更改来更新浏览器。 建立项目 使用gulp build来构建

    red-social-tdd

    如果您不想阅读, 包含1100多个视频教程,涉及各种主题,包括Laravel,现代PHP,单元测试,JavaScript等。 通过进入我们全面的视频库,提高自己和整个团队的技能水平。 Laravel赞助商 我们要感谢以下赞助商为不断...

    TDD论坛

    关于Laravel ... Laracasts包含有关各种主题的1100多个视频教程,包括Laravel,现代PHP,单元测试和JavaScript。 深入研究我们全面的视频库,提高您和您团队的技能。 Laravel赞助商 我们要感谢以下赞助商为Lar

    java8stream源码-watcher:观众项目。旨在展示技术实现示例、实现、错误、链接和文档

    和单元测试方法一起使用 看板 vs. Scrum 哪种工作方法最有效的问题并不容易 :哪种敏捷软件开发方法更适合... 关心 看板 争吵 角色和职责 没有为团队预先定义的角色 预定义角色 截止日期/交货时间表 持续交付 冲刺...

    Gatsby-Starter-TypeScript-Redux-TDD-BDD:一个很棒的Gatsby入门模板,它负责工具的设置,使您和您的团队可以直接致力于快速构建超快速的React应用程序,并放心地部署它们! :package:

    预先配置了Jest并可以进行的单元测试。 预先配置了赛普拉斯的端到端UI自动化测试。 预先将Cucumber插件安装到赛普拉斯中,以运行小Cucumber功能文件和步骤定义,以进行由内而外的行为驱动开发。 Linting已使用...

Global site tag (gtag.js) - Google Analytics