How to run a phpunit unit test with a specific dataset

王林
Release: 2024-08-01 04:09:02
Original
1038 people have browsed it

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
Copy after login

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"
Copy after login

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

testInvalidXX#9
Copy after login

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.

The above is the detailed content of How to run a phpunit unit test with a specific dataset. For more information, please follow other related articles on the PHP Chinese website!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!