TDD 是否意味着不考虑类设计? [英] Does TDD mean not thinking about class design?

查看:24
本文介绍了TDD 是否意味着不考虑类设计?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作一个有趣的角色扮演游戏,并在开发时尝试使用 TDD.我看到的许多 TDD 示例都侧重于首先创建测试,然后创建使测试通过所需的对象.

I am making a role playing game for fun and attempting to use TDD while developing it. Many of the TDD examples I see focus on creating the test first, then creating objects that are needed to get the test to pass.

例如:

[Test]
public void Character_WhenHealthIsBelowZero_IsDead()
{
   // create default character with 10 health
   Character character = new Character();
   character.SubtractHealth(20);
   Assert.That(character.IsAlive, Is.EqualTo(false));
}

因此基于此,我将创建字符类和适当的属性/方法.这看起来很好,但我的类设计真的应该来自​​不断改进我的测试吗?这比提前绘制出我的游戏需要的可能对象更好吗?例如,我通常会想到一个基本的 Character 类,然后是子类,例如 Wizard、Fighter、Theif.

So based on this I'll create the character class and appropriate properties/methods. This seems fine and all but should my class design really come out of continually refining my tests? Is that better than mapping out the possible objects that my game will need ahead of time? For example, I would normally think of a base Character class, then subclasses such as Wizard, Fighter, Theif.

或者是一种平衡的方法?我在其中绘制出可能需要的类和层次结构,但首先编写测试以验证它们是否确实需要?

Or is a balanced approach the way to go? One where I map out the possible classes and hierarchy I'll need but writing tests first to verify they are actually needed?

推荐答案

我的班级设计要不要出来不断完善我的测试?

Should my class design really come out of continually refining my tests?

是的.

TDD 是否意味着不考虑课堂设计?

Does TDD mean not thinking about class design?

绝对不是.这意味着在编写测试和其余代码的过程中考虑类设计.类设计贯穿整个红绿重构 TDD 生命周期.

Absolutely not. It means thinking about class design in the course of writing your tests, and the rest of your code. Class design is at play throughout the Red-Green-Refactor TDD life cycle.

这篇关于TDD 是否意味着不考虑类设计?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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