为追溯调整TDD成C#代码库最佳选择 [英] Best Option for Retrospective application of TDD into C# codebase

查看:135
本文介绍了为追溯调整TDD成C#代码库最佳选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个现有框架由5个C#库,自2006年以来的框架很好用,是主要的代码基础,我的大部分项目。我公司欲推出TDD软件质量的原因;通过有许多教程工作和阅读理论我明白TDD的好处。

I have an existing framework consisting of 5 C# libraries, the framework is well used since 2006 and is the main code base to the majority of my projects. My company wishes to roll out TDD for reasons of software quality; having worked through many tutorials and reading the theory I understand the benefits of TDD.

时间不是无限的,我需要做一个务实的态度这个计划。从我已经知道了,因为我看到他们有三种选择:

Time is not unlimited I need to make plans for a pragmatic approach to this. From what I know already, the options as I see them are:

一个)一个测试项目可以按顺序使用重叠的所有5库组件对象。高水平的测试一系列可能是一个起点,什么是第一次看到一个非常庞大的软件库。

A) One test project could be used in order to overlap objects from all 5 library components. A range of high level tests could be a starting point to what is first seen as a very large software library.

B)为每个5库组件的测试项目。这些项目将在其他库组件隔离的最低级别的测试功能。

B) A test project for each of the 5 library components. The projects will be testing functions at the lowest level in isolation of the other library components.

C)作为代码被广泛认为是工作,只添加单元测试bug修复或新功能。编写一个测试上有步骤重现错误在它的错误逻辑失败。然后重新因子代码,直到测试通过。现在你可以放心,这个bug是固定的,也不会在后面的周期推出

C) As the code is widely regarded as working, only add unit tests to bug fixes or new features. Write a test that fails on the logic that has the bug in it with the steps to reproduce the bug. Then re-factor the code until the tests pass. Now you can have confidence that the bug is fixed and also it will not be introduced later on in the cycle

选择哪个选项,嘲笑可能需要更换外部依赖,如:

Whichever option is chosen, "Mocking" may be needed to replace external dependencies such as:


  • 数据库

  • Web服务

  • <李>配置文件

如果任何人有任何更多的投入,这将是非常有益的。
我打算使用微软的内置MSTest的Visual Studio 2010中。

If anybody has any more input this would be very helpful. I plan to use Microsoft's inbuilt MSTest in Visual Studio 2010.

推荐答案

我们有一百万和-A-半年线的代码库。我们的方法是通过编写一些集成测试(你的选项A)启动。这些测试行使几乎占据了整个系统终端到终端:他们从一个存储库复制数据库文件,输出报告连接到数据库,对数据执行一些操作,然后以CSV和比较他们针对已知良好输出。他们是远不全面,但他们行使了大量的,我们的客户依靠我们的软件做的事情

We have a million-and-a-half line code base. Our approach was to start by writing some integration tests (your option A). These tests exercise almost the whole system end-to-end: they copy database files from a repository, connect to that database, perform some operations on the data, and then output reports to CSV and compare them against known-good output. They're nowhere near comprehensive, but they exercise a large number of the things that our clients rely on our software to do.

这些测试运行速度很慢,当然,但我们仍然可以运行所有的人不断,六年后(现在分布在八个不同的机器),因为他们抓住的东西,我们仍然没有单元测试。

These tests run very slowly, of course; but we still run all of them continuously, six years later (and now spread across eight different machines), because they catch things that we still don't have unit tests for.

一旦我们有集成测试一个体面的基础,我们花了一些时间将绕制(你的选项B)的高流量部分细粒度的测试。我们给定的时间做到这一点,因为是在我们的代码质量差的印象。

Once we had a decent base of integration tests, we spent some time adding finer-grained tests around the high-traffic parts of the system (your option B). We were given time to do this because there was a perception of poor quality in our code.

一旦我们完善的质量有一定的门槛,他们开始要求我们再次做实事。因此,我们落户到编写测试的新代码(你的选择C)节奏。此外,如果我们需要修改代码的现有一块还没有单元测试中,我们可能会花一些时间覆盖现有的功能与测试中,我们开始进行更改了。

Once we had improved the quality to a certain threshold, they started asking us to do real work again. So we settled into a rhythm of writing tests for new code (your option C). In addition, if we need to make changes to an existing piece of code that doesn't yet have unit tests, we might spend some time covering existing functionality with tests before we start making changes.

你的所有方法都有其优点,但是当你随着时间的推移获得测试覆盖率,相对收益将发生变化。对于我们的代码库,我想,我们的策略是好的;集成测试将帮助捉住试图打破依赖增加单元测试时,你犯的错误。

All of your approaches have their merits, but as you gain test coverage over time, the relative payoffs will change. For our code base, I think our strategy was a good one; integration tests will help catch any errors you make when trying to break dependencies to add unit tests.

这篇关于为追溯调整TDD成C#代码库最佳选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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