(Hopefully Simple) Question about Unit test seperation

wowemu

New Member
This question is related to PHPUnit, although it should be a global xUnit design question.I'm writing a Unit test case for a class \[code\]Image\[/code\].One of the methods of this class is \[code\]setBackgroundColor()\[/code\].There are 4 different behaviors I need to test for this method,[*]Trying to set an invalid background color. Multiple invalid parameters will be tested.[*]Trying to set a valid background color using a short hand RGB array, e.g. \[code\]array(255,255,255)\[/code\][*]Trying to set a valid background color using a standard RGB array, e.g. \[code\]array('red' => 255, 'green' => 255, 'blue' => 255)\[/code\] (this is the output format of the GD function \[code\]imagecolorsforindex()\[/code\])[*]Trying to set a valid background color using the transparent constant \[code\]IMG_COLOR_TRANSPARENT\[/code\]At the moment, I have all this contained within 1 test in my test case called \[code\]testSetBackgroundColor()\[/code\], however I'm getting the feeling these should be 4 separate tests as the test is getting quite long and doing a lot.My question is, what should I do here? Do I encapsulate all this into 1 test of the Image test case, or do I split the above into separate tests like,
  • \[code\]testSetBackgroundColorErrors\[/code\]
  • \[code\]testSetBackgroundColorShorthandRGB\[/code\]
  • \[code\]testSetBackgroundColorRGB\[/code\]
  • \[code\]testSetBackgroundColorTransparent\[/code\]
I've put the test in question here http://pastebin.com/f561fc1ab.Thank
 
Back
Top