」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 如何使用特定資料集執行 phpunit 單元測試

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

發佈於2024-08-18
瀏覽:836

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

過濾值由2部分組成:

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

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


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

版本聲明 本文轉載於:https://dev.to/pcmagas/how-to-run-a-phpunit-unit-test-with-a-specific-dataset-1g8n?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3