早就对Junit有所耳闻,一直没时间一窥其究。太懒了,昨天终于决定研究一下这个东西。下面是其主页上的一篇入门文章,俺试着翻译一下:)
JUnit Test Infected: Programmers Love Writing Tests
Testing is not closely integrated with development. This prevents you from measuring the progress of development- you can't tell when something starts working or when something stops working. Using JUnit you can cheaply and incrementally build a test suite that will help you measure your progress, spot unintended side effects, and focus your development efforts. Contents The Problem Example Testing Practices Conclusions The Problem
Every programmer knows they should write tests for their code. Few do. The universal response to "Why not?" is "I'm in too much of a hurry." This quickly becomes a vicious cycle- the more pressure you feel, the fewer tests you write. The fewer tests you write, the less productive you are and the less stable your code becomes. The less productive and accurate you are, the more pressure you feel.
Programmers burn out from just such cycles. Breaking out requires an outside influence. We found the outside influence we needed in a simple testing framework that lets us do a little testing that makes a big difference.
The best way to convince you of the value of writing your own tests would be to sit down with you and do a bit of development. Along the way, we would encounter new bugs, catch them with tests, fix them, have them come back, fix them again, and so on. You would see the value of the immediate feedback you get from writing and saving and rerunning your own unit tests.
Unfortunately, this is an article, not an office overlooking charming old-town Zürich, with the bustle of medieval commerce outside and the thump of techno from the record store downstairs, so we'll have to simulate the process of development. We'll write a simple program and its tests, and show you the results of running the tests. This way you can get a feel for the process we use and advocate without having to pay for our presence.
Junit让程序员爱上测试
往往来说,测试和开发并不是紧密地集成在一起的,这会让妨碍你估量开发的进度-你不清楚一些东西什么时间开始工作或者停止工作。用Juint你可以创建一个简单的、增量式的测试集合,帮助你评估开发的进度,spot unintended side effects,集中精力进行你的开发。
目录
问题
例子
测试练习
结论
问题
每个程序员都清楚应该为自己的代码写一些测试,但很少有人会这样做。通常对于这个问题的回答就是“我太忙了,要赶进度啊!”。很快这就成为一个恶性循环-压力越大,你写的测试越少。你写的测试越少,你写出来的高质量的代码就越少并且将很不稳定。并且将接着导致你承受更大的压力。
程序员的精力就在这样的恶性循环中被耗费掉。想要打破它需要一种外界的影响。我们发现所谓的这种外界的影响,其实就是一个简单的测试框架,它可以让我们通过做很少的测试,但是你会发现有一些很大的不同。
让你认识到写自己的测试的价值的最好的办法就是坐下来进行一点开发。在此过程中,我们会遇到一些bugs,通过测试找到bug,修复bug,然后再测试,发现bug再修复等等。你会发现从你写测试,进行测试和重复测试中获得的及时反馈很有利用价值。
当然,这里只是一篇文章,不是an office overlooking charming old-town Zürich, with the bustle of medieval commerce outside and the thump of techno from the record store downstairs,所以我们只能模仿开发的进行情况。会给出一些简单的程序和它的测试,并展示执行测试的结果。通过这样你可以明白一些我们用到的步骤,然后以后即使我们不说你也会提倡这样做。
本文地址:http://com.8s8s.com/it/it12731.htm