Q:如果testReserve()執行失敗,testUnReserve()會執行嗎?
A:是不會的,當被依賴的測試案例如果測試失敗,那依賴的測試就會忽略執行。
我們可以試著將testReserve()故意測試失敗,只需要針對事件物件的getAttendNumber()斷言的預期值,從1改成0就可以讓testReserve()測試失敗,接著再執行測試:
? how-to-write-a-phpunit-testcase git:(master) ? phpunit --bootstrap vendor/autoload.php tests/EventTest.php
PHPUnit 5.4.8 by Sebastian Bergmann and contributors.
FS..
Time: 110 ms, Memory: 10.00MB
There was 1 failure:
1) EventTest::testReserve
Failed asserting that 1 matches expected 0.
/Users/wangzhihao/git/how-to-write-a-phpunit-testcase/tests/EventTest.php:52
FAILURES!
Tests: 4, Assertions: 14, Failures: 1, Skipped: 1.
數據提供者,能提供多次的測試數據進行多次的測試。
原文轉自:http://www.jianshu.com/p/ba6829a6f3ec