我正试图使用EcomDev_PHPUnit包在Magento上进行单元测试,但我在配置它时遇到了一些问题。我已经在这里发布了这个问题和适用于我的解决方案-
MAGENTO.stackexchange.com-使用EcomDev_PHPUnit 编写单元测试用例的指针
现在,我有一个非常普通的问题,
class Webservice_Clientservice_Test_Model_ClientserviceimplTest extends EcomDev_PHPUnit_Test_Case{
public function testBasicFunctionality(){
try{
//Mage::log("testBasicFunctinality");
$this->assertSame(true,false);
}catch(Exception $e){
Mage::logException($e);
}
}
}
当我使用运行此测试时
phpunit --group Webservice_Clientservice
我得到以下,
phpunit --group Webservice_Clientservice
PHPUnit 3.7.22 by Sebastian Bergmann.
Configuration read from /mnt/www/dev.magento.com/phpunit.xml.dist
..
Time: 3 seconds, Memory: 22.25Mb
OK (2 tests, 2 assertions)
我原以为断言会失败,测试用例最终会失败。。。它怎么会过去?真的有点不对劲。。。True不能等于false:(而且,测试用例也运行了两次?我不知道为什么……
如果用try catch
块封装测试,则测试不会失败。
// failing test
public function testFail() {
$this->assertSame(true, false);
}
// successful test
public function testSuccess() {
try {
$this->assertSame(true, false);
} catch (Exception $e) {
echo "go on";
}
}
如果你想强制测试失败,你可以使用fail
方法:
public function testForceFail() {
$this->fail('Failed Yeah');
}