使用测试驱动开发时的俄罗斯方块验收测试

发布于 2024-09-10 21:23:40 字数 656 浏览 0 评论 0原文

我想尝试使用 TDD 来实现俄罗斯方块游戏。

根据我在阅读以测试为指导的不断发展的面向对象软件,我应该首先定义我的验收测试。如果我是对的,那么进行 TDD 时的验收测试就像用例一样被定义。

定义一个良好的首次验收测试非常重要,该测试将作为应用程序的“骨架”,因此它应该有点简单。

我选择了以下 2 个验收测试作为我的第一个实施:

  1. 游戏开始,玩家关闭它。
  2. 游戏开始,玩家什么都不做。他最终还是输了。

这两个验收测试是好的开始测试吗?接下来的验收测试什么是好的?我可以想到类似

  • 游戏开始后只有方形棋子掉落。玩家以这样的方式放置它们,使得线条总是“爆炸”,使得游戏在 100 个游戏步骤后仍然没有结束。

但我觉得这有点尴尬,因为在真正的俄罗斯方块游戏中,你总是会有不同的棋子掉落,而这就是验收测试应该做的事情。

另外,在执行(2)时,我有点想尝试一次性实现所有内容,我认为这并不是在实现第二个验收测试时假装的。我想我们的想法是只在 6 到 7 次之后才实现游戏,而不是在第二次。我说得对吗?

谢谢

I want to try to implement the Tetris Game using TDD.

From what I've come to understand when reading Growing Object-Oriented Software, Guided by Tests, I should start by defining what would be my Acceptance tests. If I am right, Acceptance tests when doing TDD are defined just like Use Cases.

It is of great importance to define a good first Acceptance Test that will work as "skeleton" of the App, so it should be kind of simple.

I've choosen the following 2 Acceptance Tests as my first to implement:

  1. The Game starts and the Player closes it.
  2. The Game starts and the Player does nothing. He eventually loses.

Are these 2 acceptance tests good starting tests? What would be good next acceptance tests? I could think of something like

  • The game starts and only square pieces drop. The player puts them all in such a way that the lines always "explode", making the Game after 100 game-steps still be not over.

but I feel this is kind of awkward, as in a real Tetris game you would always have different pieces falling, and that is what Acceptance Testing should be about.

Also, I feel kind of tempted to just try to implement everything in one go when doing (2), which I think is not one pretends when implementing the second Acceptance Test. I guess the idea would be to only have the game implemented after like 6-7 of them, not on the second. Am I right?

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

因为看清所以看轻 2024-09-17 21:23:41

您需要从测试中删除游戏中的随机性。是的,这意味着测试并不能完美地复制游戏,但这也意味着您拥有可重复的测试,这具有更大的价值。隔离差异 - 将 PieceProvider 传递到您的游戏中;对于真实游戏,传递 RandomPieceProvider,但对于测试,传递 SpecifiedPieceProvider。现在它们之间只有一点点差异,但差异应该小到不重要;您仍然可以放心地测试游戏的所有其他方面。

You will want to remove the randomness that belongs in your game from your tests. Yes, this means that the test doesn't perfectly duplicate the game, but it also means you have repeatable tests, and that's of greater value. Isolate the differences - pass a PieceProvider into your game; for the real game pass a RandomPieceProvider, but for the tests pass in a SpecifiedPieceProvider. Now you have just a tiny bit of difference between them, but the difference ought to be so small as not to matter; you can still test all other aspects of the game with confidence.

雨夜星沙 2024-09-17 21:23:41

从一个简单的块列表开始。假设没有玩家,方块会以某种方式堆积起来,然后溢出。如果块未正确堆叠或程序未检测到溢出,则测试失败。

Start out with a simple list of blocks. Assuming no player, the blocks will stack up in a certain way and then spill over. Your test fails if the blocks don't stack up right or the program does not detect spill over.

无需解释 2024-09-17 21:23:40

我首先会考虑游戏场地,以及在一些已定义的块被丢弃的帧数之后它看起来是什么样子。例如使用 Cucumber

Scenario: dropping the first square
  Given an empty 10x2 field

  When a square is dropped at column 4
  And 48 frames have passed

  Then the field should contain a square at (4, 1)

  When 48 frames have passed
  Then the field should contain a square at (4, 2)

Scenario: Dropping a square on a full stack
  Given an empty 10x2 field
  And a square at (4, 2)

  When a square is dropped at column 4
  And 48 frames have passed

  Then the game should be over

如果您喜欢 Cucumber 功能规范的外观,您可能想尝试 Cuke4Nuke for .Net 或 Cuke4Duke 用于 Java。

I would think first about the game field and what it looks like after a number of frames with some defined blocks dropped. For example using Cucumber:

Scenario: dropping the first square
  Given an empty 10x2 field

  When a square is dropped at column 4
  And 48 frames have passed

  Then the field should contain a square at (4, 1)

  When 48 frames have passed
  Then the field should contain a square at (4, 2)

Scenario: Dropping a square on a full stack
  Given an empty 10x2 field
  And a square at (4, 2)

  When a square is dropped at column 4
  And 48 frames have passed

  Then the game should be over

If you like the look of Cucumber feature specs, you might want to try Cuke4Nuke for .Net or Cuke4Duke for Java.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文