2013-07-26 33 views
2

我想在Magento上使用EcomDev_PHPUnit包进行单元测试,并且在配置它时遇到了一些问题。我已经发布了这个问题,并在这里为我工作的解决方案 -Magento phpunit断言 - assertEquals(true,false)

MAGENTO.stackexchange.com-Pointers to write unit test cases using 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) 

我在期待断言会失败,测试用例最终会失败......它是如何通过的?有些东西真的是错的......真的不能等于假:(而且,测试用例也运行两次?我不知道为什么......

+0

你找出一个解决方案 –

+0

哪里是'@group '注释? – sectus

回答

1

如果你用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'); 
}