Test Driven or Test First?

I recently got into a discussion with Cobbie Behrend, following on from some comments I’d made about test-driven development. I’d said that I rarely do test-first, but I often do test-driven coding.

Cobbie pushed me to distinguish between them, particularly in light of references on the Object Mentor site, the C2 wiki, and other sites, which seem to equate the two.

I disagree—test-first is different than test-driven development.

For me, test-driven development is an important way of thinking about coding. It’s about using tests to gain perspective on your design and implementation. You listen to what the tests are telling you, and alter to code accordingly. Finding it hard to test something in isolation? Refactor your code to reduce coupling. Is it impossible to mock out a particular subsystem? Look at adding facades or interfaces to make the separation cleaner. Tests drive the design, and tests verify the implementation.

Test-first development takes this a step further. In test-first, you never write a line of production code until you first have a failing test that will be "fixed" by the code you write. Want to write a new class? First write a test that instantiates it, watch the test fail, and then implement the class body to fix the broken test.

Test-first development is a subclass of test-driven development. It has every benefit of test-driven development, and then adds a ritual component of testing and coding in a certain order. The intent of the ritual is to ensure that tests are always produced.

For me, test-driven development is an essential part of coding. Test-first coding, however, often strikes me as unnecessarily high-church. So I distinguish the two, in the same way that I distinguish agile methods from eXtreme Programming. Test-driven is an important, almost universal practice. Test-first is a particular implementation, and it isn’t always applicable.

I don’t know if this helps Cobbie in his search for meaning, though…

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值