I have a class that access web services. It can optionally cache results. So I want to write two test classes. The first one (Ws_Test) runs tests without caching. The second one (WsCached_Test) extends the first and runs the same tests but with cache enabled.
In theory that solves my problem, but when I run ‘all tests’ only the second test class (WsCached_Test) is run. Seems like PHPUnit assumes the class has already been completely tested when WsCached_Test is run.
class Ws_Test extends PHPUnit_Framework_TestCase
{
public function setUp()
{
$this->ws = new Ws();
}
// lots of tests
}
class WsCached_Test extends Ws_Test
{
public function setUp()
{
$this->ws = new Ws();
$this->ws->setCacheResults(true);
}
// inherits lots of tests
}
I don’t know if this will solve the problem, but my first attempt at a fix would be to make the base class abstract and have two subclasses:
WsCached_TestandWsUncached_Test.The name
BaseWsTesteris chosen to keep PHPUnit from thinking it’s a test case to be run, and its abstractness should help. If this doesn’t work, movesetUp()down into each subclass and remove it from the base class.