"If a worker wants to do his job well, he must first sharpen his tools." - Confucius, "The Analects of Confucius. Lu Linggong"
Front page > Programming > How to run a phpunit unit test with a specific dataset

How to run a phpunit unit test with a specific dataset

Published on 2024-08-18
Browse:711

How to run a phpunit unit test with a specific dataset

Today I was running my tests and had a failing test:

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

I tried to debug the issue, but I had a lot of data in my dataset. The failing case was only with a specific dataset and I needed to run the failing test testInvalidXX with only the soecific one (dataset #9).

In order to do this I've launched the phpunit like this:

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

In the command above, pay attention to the --filter value provided. The filter value is:

testInvalidXX#9

The filter value is consisted of 2 parts:

  1. The test name testInvalidXX
  2. The dataset index #9

By using this filter, PHPUnit will only run the specified test case with the dataset index #9, allowing you to focus on debugging the specific failure.


This tutorial should help you run a specific test with a particular dataset index using PHPUnit.

Release Statement This article is reproduced at: https://dev.to/pcmagas/how-to-run-a-phpunit-unit-test-with-a-specific-dataset-1g8n?1 If there is any infringement, please contact [email protected] delete
Latest tutorial More>

Disclaimer: All resources provided are partly from the Internet. If there is any infringement of your copyright or other rights and interests, please explain the detailed reasons and provide proof of copyright or rights and interests and then send it to the email: [email protected] We will handle it for you as soon as possible.

Copyright© 2022 湘ICP备2022001581号-3