如何处理单元测试的一个大项目 [英] How to approach unit testing in a large project

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

问题描述

我们有一个开始得到大的一个项目,我们需要开始应用单元测试我们开始重构。什么是应用单元测试已经存在的项目的最佳方法是什么?我(有点),用于从地上爬起来,在这里我写的测试与代码的第一行起一起做。我不知道如何下手的时候功能已经到位。我是不是应该开始从资源库中的每个方法编写测试?或者我应该从控制器下启动

We have a project that is starting to get large, and we need to start applying Unit Tests as we start to refactor. What is the best way to apply unit tests to a project that already exists? I'm (somewhat) used to doing it from the ground up, where I write the tests in conjunction with the first lines of code onward. I'm not sure how to start when the functionality is already in place. Should I just start writing test for each method from the repository up? Or should I start from the Controllers down?

更新:
澄清该项目的大小...我真的不知道该怎么形容这只是说有8控制器和167文件具有.cs文件,遍布约7个月的开发..

update: to clarify on the size of the project.. I'm not really sure how to describe this other than to say there's 8 Controllers and about 167 files that have a .cs extension, all done over about 7 developer months..

推荐答案

你似乎知道,测试改装到现有项目并不容易。你,你去写测试的方法是更好的办法。你的问题是两个过程之一,技术 - 测试必须由每个人都被要求或没有人会使用它们。

As you seem to be aware, retrofitting testing into an existing project is not easy. Your method of writing tests as you go is the better way. Your problem is one of both process and technology- tests must be required by everyone or no one will use them.

我听说过,并同意该建议是,你不应试图一次全部环绕在现有的代码库的测试。你永远不会结束。通过努力测试到漏洞修复启动流程 - 每个固定的bug得到了检验。这将开始一段时间的工作测试到现有的代码。新的代码必须的总是的当然有测试。最终,你会得到覆盖率达一个合理的比例,但它需要时间。

The recommendation I've heard and agree with is that you should not attempt to wrap tests around an existing codebase all at once. You'll never finish. Start by working testing into your bugfix process- every fixed bug gets a test. This will start to work testing into your existing code over time. New code must always have tests, of course. Eventually, you'll get the coverage up to a reasonable percentage, but it will take time.

我已经推荐给我一个很好的书的有效合作与遗留代码通过迈克尔羽毛。标题并没有真正表现出它,但是测试的工作到一个现有的代码库是本书的一大主题。

One good book I've had recommended to me is Working Effectively With Legacy Code by Michael C. Feathers. The title doesn't really demonstrate it, but working testing into an existing codebase is a major subject of the book.

这篇关于如何处理单元测试的一个大项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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