教你一步一步寫一個phpunit testcase(11)

發表于:2017-06-01來源:葉左左作者:葉左左點擊數: 標簽:PHPUnit
Q:如果testReserve()執行失敗,testUnReserve()會執行嗎? A:是不會的,當被依賴的測試案例如果測試失敗,那依賴的測試就會忽略執行。 我們可以試著將

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.

Data Providers(數據提供者)

數據提供者,能提供多次的測試數據進行多次的測試。

原文轉自:http://www.jianshu.com/p/ba6829a6f3ec

国产97人人超碰caoprom_尤物国产在线一区手机播放_精品国产一区二区三_色天使久久综合给合久久97