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