TDD与单元测试 [英] TDD vs. Unit testing

查看:115
本文介绍了TDD与单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的公司对于单元测试我们的代码还很陌生.我已经阅读了一段时间的TDD和单元测试,并深信它们的价值.我试图说服我们的团队,TDD值得我们学习和改变关于编程方式的思维方式,但这是一个挣扎.这使我想到了我的问题.

My company is fairly new to unit testing our code. I've been reading about TDD and unit testing for some time and am convinced of their value. I've attempted to convince our team that TDD is worth the effort of learning and changing our mindsets on how we program but it is a struggle. Which brings me to my question(s).

在TDD社区中,有很多人对编写测试然后编写代码非常虔诚(我和他们在一起),但是对于一个在TDD中苦苦挣扎的团队来说,妥协仍会带来额外的好处吗?

There are many in the TDD community who are very religious about writing the test and then the code (and I'm with them), but for a team that is struggling with TDD does a compromise still bring added benefits?

一旦编写了代码(也许是检入代码的要求),我可能可以成功地使团队编写单元测试,并且我的假设是编写这些单元测试仍然有价值.

I can probably succeed in getting the team to write unit tests once the code is written (perhaps as a requirement for checking in code) and my assumption is that there is still value in writing those unit tests.

将陷入困境的团队带入TDD的最佳方法是什么?失败的是,即使在编写代码之后,仍然值得编写单元测试吗?

What's the best way to bring a struggling team into TDD? And failing that is it still worth writing unit tests even if it is after the code is written?

编辑

我摆脱的是,对于我们而言,在编码过程中的某个位置开始单元测试非常重要.对于团队中支持此概念的人员,应开始朝着TDD进行更多测试并首先进行测试.感谢大家的投入.

What I've taken away from this is that it is important for us to start unit testing, somewhere in the coding process. For those in the team who pickup the concept, start to move more towards TDD and testing first. Thanks for everyone's input.

跟进

我们最近开始了一个新的小型项目,而团队中的一小部分使用了TDD,其余的则在代码之后编写了单元测试.在包装完项目的编码部分之后,那些编写了代码后的单元测试的人惊讶地发现TDD编码器已经完成并且具有更可靠的代码.这是赢得怀疑论者的好方法.我们仍然有很多成长的烦恼,但是意志之战似乎已经结束.感谢所有提供建议的人!

We recently started a new small project and a small portion of the team used TDD, the rest wrote unit tests after the code. After we wrapped up the coding portion of the project, those writing unit tests after the code were surprised to see the TDD coders already done and with more solid code. It was a good way to win over the skeptics. We still have a lot of growing pains ahead, but the battle of wills appears to be over. Thanks for everyone who offered advice!

推荐答案

如果团队在实施TDD时步履维艰,但他们并未在之前创建任何单元测试...然后通过在其代码之后创建单元测试来启动它们被写.即使是在代码之后编写的单元测试也比根本没有单元测试要好!

If the team is floundering at implementing TDD, but they weren't creating any Unit Tests before...then start them off by creating Unit Tests after their code is written. Even Unit tests written after the code are better than no Unit Tests at all!

一旦他们精通单元测试(及其附带的所有内容),那么您就可以让他们先创建测试,然后再编写代码.

Once they're proficient at Unit Testing (and everything that comes with it), then you can work on getting them to create the tests first...and code second.

这篇关于TDD与单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆