0
我最近开始使用单元测试,迄今为止一直是一个爆炸。测试夹具数据
但是,我遇到了一种情况,那就是我的方法显然是错误的,我无法将自己的头围绕在“好”的解决方案上。
该代码的上下文是查看用symfony编写的电视广播时间表的应用程序,用sfPHPUnit2Plugin进行测试。
public function testLoadChannelBroadcasts() {
$Start = new DateTime();
$End = new DateTime();
$Channels = ChannelTable::getChannelsWithBroadcastsTouchingTimeSpan($Start, $End);
foreach ($Channels as $Channel) {
$Channel->loadBroadcastsTouchingTimeSpan($Start, $End);
}
// test data
$Broadcasts = $Channels[0]->Broadcasts;
$assertion = $Broadcasts[0]->getDateTimeObject('start') <= $Start
&& $Broadcasts[0]->getDateTimeObject('end') >= $Start;
$this->assertTrue($assertion, 'starts before scope, ends inside scope');
$assertion = $Broadcasts[1]->getDateTimeObject('start') >= $Start
&& $Broadcasts[1]->getDateTimeObject('end') <= $End;
$this->assertTrue($assertion, 'starts inside scope, ends inside scope');
$assertion = $Broadcasts[2]->getDateTimeObject('start') >= $Start
&& $Broadcasts[2]->getDateTimeObject('end') >= $End;
$this->assertTrue($assertion, 'starts inside scope, ends outside scope');
$LongBroadcast = $Channels[1]->Broadcasts[0];
$assertion = $LongBroadcast->getDateTimeObject('start') <= $Start
&& $LongBroadcast->getDateTimeObject('end') >= $End;
$this->assertTrue($assertion, 'starts before scope, ends after scope');
}
试验通信的方法的目的,但数据(夹具)测试在很大程度上依赖于什么数据中包含的假设。有没有更好的方法呢?