【发布时间】:2010-01-21 10:46:12
【问题描述】:
这个问题与 PHPUnit 相关,虽然它应该是一个全球性的 xUnit 设计问题。
我正在为 Image 类编写单元测试用例。
这个类的方法之一是setBackgroundColor()。
我需要为此方法测试 4 种不同的行为,
- 试图设置无效的背景颜色。将测试多个无效参数。
- 尝试使用简写 RGB 数组设置有效的背景颜色,例如
array(255,255,255) - 尝试使用标准 RGB 数组设置有效的背景颜色,例如
array('red' => 255, 'green' => 255, 'blue' => 255)(这是GD函数imagecolorsforindex()的输出格式) - 尝试使用透明常量
IMG_COLOR_TRANSPARENT设置有效的背景颜色
目前,我在名为testSetBackgroundColor() 的测试用例中将所有这些都包含在 1 个测试中,但是我觉得这些应该是 4 个单独的测试,因为测试变得很长并且做了很多工作。
我的问题是,我应该在这里做什么?我是将所有这些封装到 Image 测试用例的 1 个测试中,还是将上述内容拆分为单独的测试,例如,
testSetBackgroundColorErrorstestSetBackgroundColorShorthandRGBtestSetBackgroundColorRGBtestSetBackgroundColorTransparent
我在http://pastebin.com/f561fc1ab 提出了测试问题。
谢谢
【问题讨论】:
-
+1,好问题,写得很好。
标签: php unit-testing design-patterns phpunit