9951 explained code solutions for 126 technologies


phpunitHow to run only certain methods in PHPUnit?


You can run only certain methods in PHPUnit by using the --filter option.

For example, to run only the testAdd() method in the CalculatorTest class, you can use the following command:

phpunit --filter testAdd CalculatorTest

This will run only the testAdd() method in the CalculatorTest class.

The parts of the command are:

  • phpunit: the command to run PHPUnit
  • --filter: the option to specify which method to run
  • testAdd: the name of the method to run
  • CalculatorTest: the name of the class containing the method

For more information, see the PHPUnit documentation.

Edit this code on GitHub