在Brownfield应用程序中实施单元测试的首要任务是什么? [英] What are the first tasks for implementing Unit Testing in Brownfield Applications?

查看:55
本文介绍了在Brownfield应用程序中实施单元测试的首要任务是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您是否首先重构您的SQL?您的建筑?还是你的代码库? 您会更改语言吗?您是否丢弃一切并从头开始? [不重构]

Do you refactor your SQL first? Your architecture? or your code base? Do you change languages? Do you throw everything away and start from scratch? [Not refactoring]

推荐答案

我正在将单元测试添加到大型的传统意大利面条式代码库中.

I'm adding unit testing to a large, legacy spaghetti codebase.

我的方法是,当被要求解决问题时,我尝试围绕与当前任务相关的部分代码库创建一个新包装器.这个新的包装器是使用TTD开发的(首先编写测试).有些时候,将插入到未经单元测试的遗留代码中.在其他时候,我会复制现有模块,并开始对其进行严重的暴力攻击.有时我会从头开始重写功能.

My approach is, when asked to solve a problem, I try to create a new wrapper around the part of the code-base which is relevant to my current task. This new wrapper is developed using TTD (writing the test first). Some of the time calling into the non-unit tested legacy code. At other times I make a new copy of an existing module and start to do serious violence to it. Sometimes I rewrite functionality from scratch.

但是,由于我一直对其进行了很好的测试,所以我感到可以控制.

But as I'm keeping it fairly well tested I feel pretty in control.

我发现此代码库是经过大量复制和粘贴而开发的,一旦我理解了某个特定部分,并从中提取了一些功能(首先进行测试). ..这些功能通常可以在许多其他地方使用,因此用我自己的,经过单元测试的库替换遗留代码的比率提高了.

What I find with this code-base, which has been developed with far too much copy and pasting, is that once I get an understanding a particular part, and extract some functions from it (which are done test-first) ... these functions often turn out to be usable in many other places and so the rate of replacing the legacy code with my own, unit tested libraries increases.

我不(也无权)尝试重写代码或将测试添加到当前问题未解决的部分代码(通常是我要修复的错误),但是我确实有一个相当不错的选择在任何可能涉及到的事情上都采取积极主动的立场.

I don't (and have no authority to) try to rewrite or add tests to parts of the code that are not touched by my current problem (usually a bug I'm trying to fix) but I do have a fairly aggressive proactive stance on anything that is touched and might be relevant.

更新:Penguinix问:您使用哪种语言?您建议使用特定的测试工具吗?"

Update : Penguinix asked : "What languages do you work in? Is there a specific Testing Harness you recommend?"

现在我正在……呃……腮腺炎!但是,同样的原理在任何地方都适用.

Right now I'm working in ... er ... Mumps! But the same principle works anywhere.

MinUnit改变了我对UT的理解: http://www.jera .com/techinfo/jtns/jtn002.html

Something that transformed my understanding of UT was MinUnit : http://www.jera.com/techinfo/jtns/jtn002.html

当我看到MinUnit时,这对我来说是一个禅宗"的启迪时刻.它消除了我对单元测试的误解,因为单元测试是一件复杂的事情,需要复杂的OO框架等.我了解到UT只是在编写大量测试.您可以在3分钟内用自己喜欢的任何一种语言来编写自己的线束".上车去做吧.

When I saw MinUnit, that was kind of a "zen" moment of enlightenment for me. It stripped away the misunderstandings I had about unit testing being something complicated requiring sophisticated OO frameworks etc. I understood that UT was just about writing a bunch of tests. The "harness" you can write yourself, in about 3 minutes, in any language you like. Just get on and do it.

这篇关于在Brownfield应用程序中实施单元测试的首要任务是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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