how to test specific test class using phpunit in laravel

Gujarat Santana picture Gujarat Santana · Aug 24, 2016 · Viewed 50.3k times · Source

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

Answer

Gujarat Santana picture Gujarat Santana · Aug 24, 2016

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.