I have a class and few functions that I need to test against multiple sets of data. I load these data from flat files. I understand that I can load a file in the setUp() method and run my tests, but how do I load multiple sets of data and test the same functions against those data?
+1
A:
class MyTestCase extends PHPUnit_Framework_TestCase {
private $_testObjects = array();
public function setUp()
{
// load the files, unserialize the objects
// and store them in the $_testObjects array
}
public function getTestObjects()
{
return $this->_testObjects;
}
public function testA()
{
foreach ($this->getTestObjects() as $obj) {
// execute assertion/s
}
}
public function testB()
{
foreach ($this->getTestObjects() as $obj) {
// execute assertion/s
}
}
// ...
}
nuqqsa
2010-06-03 20:42:06
I did something similar already, thank you for the answer :)Its almost the same, but instead of all files in the setUp() function, I loaded them individually inside each of my functions. My objects are fairly heavy, so don't want to load all of them in one shot.Thanks again.
2010-06-06 14:06:35
6 half dozen. I really think you should try testing loading them in one shot. What are you actually trying to test for? Deserialize/Some logic/Reserialize? Don't you actually have the source code files in which the objects are initially created? I would test with the original source code files.
Gutzofter
2010-06-08 01:52:06