Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to test specific test class using phpunit in laravel

I want to test specific testClass in my project since there are a lot of test class that's failure and I just want to test one Class at a time.

I've created the test Class in following folder \test\repositories\ApplicationVersionFormat.php :

<?php use App\Repositories\ApplicationVersionFormat;  class ApplicationVersionFormatTest extends \TestCase {   public function testValidFormat()   {     $version = '1.2.3';     $appVersion = new ApplicationVersionFormat();     $this->assertEquals(true,$appVersion->isValidVersion($version));   }    public function testInvalidFormat()   {     $version = '11.2.3';     $appVersion = new ApplicationVersionFormat();     $this->assertEquals(false,$appVersion->isValidVersion($version));   }    public function testInvalidFormat2()   {     $version = '1.22.3';     $appVersion = new ApplicationVersionFormat();     $this->assertEquals(false,$appVersion->isValidVersion($version));   }    public function testInvalidFormat3()   {     $version = '1.2.33';     $appVersion = new ApplicationVersionFormat();     $this->assertEquals(false,$appVersion->isValidVersion($version));   }    public function testInvalidFormat4()   {     $version = '11.22.33';     $appVersion = new ApplicationVersionFormat();     $this->assertEquals(false,$appVersion->isValidVersion($version));   } } 

so I've tried this follwing command but none of this works :

  • phpunit "repositories\AppVersionTest". => Cannot open file "test/repositories/AppVersionTest.php"
  • phpunit "test\repositories\AppVersionTest". => Cannot open file "test/repositories/AppVersionTest.php"
  • phpunit --filter "repositories\AppVersionTest". => No tests executed!
  • phpunit --testsuite "repositories\AppVersionTest". => No tests executed!

any help? thanks

like image 520
Gujarat Santana Avatar asked Aug 24 '16 08:08

Gujarat Santana


People also ask

How do I run a PHPUnit test case?

How to Run Tests in PHPUnit. You can run all the tests in a directory using the PHPUnit binary installed in your vendor folder. You can also run a single test by providing the path to the test file. You use the --verbose flag to get more information on the test status.

What is PHPUnit testing?

PHPUnit is a unit testing framework for the PHP programming language. It is an instance of the xUnit architecture for unit testing frameworks that originated with SUnit and became popular with JUnit. PHPUnit was created by Sebastian Bergmann and its development is hosted on GitHub.

What is PHPUnit Laravel?

Use Laravel Unit Testing to Avoid Project-Wrecking Mistakes. Pardeep Kumar. 7 Min Read. PHPUnit is one of the most well known and highly optimized unit testing packages of PHP. It is a top choice of many developers for rectifying different developmental loopholes of the application.


1 Answers

After trying several ways, I found out that I don't need to include the folder to test the specific test class. This works for me it runs all the test on the class:

phpunit --filter ApplicationVersionFormatTest

I think it's because my ApplicationVersionFormatTest extend The TestCase and return application instance which serves as the "glue" for all the components of Laravel.

like image 128
Gujarat Santana Avatar answered Sep 21 '22 18:09

Gujarat Santana