PASSWORD RESET

Your destination for complete Tech news

How to test specific test class using PHPUnit in Laravel?

2.39K 0
< 1 min read

To run a specific test class using PHPUnit in Laravel, you can use the phpunit command and pass the path to the test class file as an argument.

For example, suppose you have a test class called ExampleTest located at tests/Unit/ExampleTest.php. You can run this test class using the following command:

vendor/bin/phpunit tests/Unit/ExampleTest.php

If you want to run a specific test method within the test class, you can use the --filter option and specify the name of the test method.

For example:

vendor/bin/phpunit tests/Unit/ExampleTest.php --filter testMethodName

This will run only the testMethodName method within the ExampleTest class.

You can also use the --group option to run a specific group of tests within the test class. To specify a group, you can use the @group annotation in your test methods.

For example:

/**
 * @group slow
 */
public function testSlowMethod()
{
    // test code goes here
}

/**
 * @group fast
 */
public function testFastMethod()
{
    // test code goes here
}

You can then run the tests in the slow group using the following command:

vendor/bin/phpunit tests/Unit/ExampleTest.php --group slow

Leave A Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.