我应该练习“模仿主义者"吗?或“古典" TDD? [英] Should I practice "mockist" or "classical" TDD?

查看:63
本文介绍了我应该练习“模仿主义者"吗?或“古典" TDD?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读(并重新阅读了)马丁·福勒(Martin Fowler)的不是存根".他在其中定义了 TDD的两种不同方法:古典"和模拟" .他试图回答问题"那么我应该是古典主义者还是嘲笑主义者?",但他承认,他从未在玩具以外的任何东西"上尝试过嘲讽TDD.所以我想在这里问这个问题.好的答案可能会重复Fowler的论点(但希望可以更清楚),或者添加自Fowler于2007年1月上次更新论文以来他从未想到或其他人提出的论点.

I've read (and re-read) Martin Fowler's Mocks Aren't Stubs. In it, he defines two different approaches to TDD: "Classical" and "Mockist". He attempts to answer the question "So should I be a classicist or a mockist?", but he admits that he has never tried mockist TDD on "anything more than toys." So I thought I'd ask the question here. Good answers may repeat Fowler's arguments (but hopefully more clearly) or add arguments that he didn't think of or that others have come up with since Fowler last updated the essay back in January 2007.

推荐答案

我认为您无需选择一个.两者都有其优点和缺点,并且都是工具箱的工具. "Mockist" tdd使您可以更灵活地进行测试,而传统TDD的测试则使您的测试变得不那么脆弱,因为它们倾向于更多地关注输入/输出而不是实际实现.在进行模拟单元测试时,似乎在更改实现时会有更多测试中断.

I don't think you need to choose one over the other. Both have their advantages and disadvantages and both are tools for your toolbox. "Mockist" tdd makes you a bit more flexible in what you can test while classical TDD makes your tests a bit less brittle because they tend to look more at the input/vs output instead of looking at the actual implementation. When doing mockist unit testing I seem to have more tests break when changing the implementation.

我尽可能尝试使用经典的tdd(尽管我经常使用模拟框架来快速设置存根).有时我注意到我一次开始太多测试,或者我需要太多对象来设置测试.到那时,模拟测试通常可以帮助您设置较小的测试.

I try to use classical tdd whenever possible (although i often use a mocking framework to set up the stubs quickly). Sometimes I notice I start testing too much at one time or i need too many objects to set up a test. That's when mockist testing can often help you set up smaller tests.

这都是非常抽象的,所以我希望我能理解

This is all quite abstract so I hope i make sense

这篇关于我应该练习“模仿主义者"吗?或“古典" TDD?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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