首頁  >  文章  >  後端開發  >  如何使用特定資料集執行 phpunit 單元測試

如何使用特定資料集執行 phpunit 單元測試

王林
王林原創
2024-08-01 04:09:021116瀏覽

How to run a phpunit unit test with a specific dataset

今天我正在運行測試,但測試失敗了:

Tests\Common\BusinessLogic\XXX\XXLogicTest::testInvalidXX with data set #9 ([['dsadsa', 'dsafsdfsd', 1234.23, -1234.23, '', 'dsadsa']]) Failed asserting that 1 matches expected 0.

/var/www/html/tests/Common/BusinessLogic/Asfalistiko/FormSectionELogicTest.php:102 /var/www/html/tests/Common/BusinessLogic/XXX/XXLogicTest.php:301

我嘗試調試這個問題,但我的資料集中有很多數據。失敗的情況只涉及特定的資料集,我需要只使用特定的資料集(資料集 #9)來執行失敗的測試 testInvalidXX。

為了做到這一點,我啟動了 phpunit,如下所示:

./vendor/bin/phpunit ./tests/Common/BusinessLogic/XXX/XXLogicTest.php --filter="testInvalidXX#9"

在上面的指令中,請注意提供的 --filter 值。過濾值為:

testInvalidXX#9

過濾值由兩部分組成:

  1. 測試名稱 testInvalidXX
  2. 資料集索引#9

透過使用此篩選器,PHPUnit 將僅執行資料集索引 #9 的指定測試案例,讓您可以專注於偵錯特定的故障。


本教學課程應該可以幫助您使用 PHPUnit 對特定資料集索引執行特定測試。

以上是如何使用特定資料集執行 phpunit 單元測試的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn