Using phpunit
command Laravel will run all unit tests in our project.
How to run one or specific Unit Tests in Laravel 5.1
?
I just want to run testFindToken
from my test suite.
JavaScript
x
<?php
use Mockery as m;
use AppModelsAccessToken;
use IlluminateFoundationTestingWithoutMiddleware;
class AccessTokenRepositoryTest extends TestCase
{
use WithoutMiddleware;
public function setUp()
{
parent::setUp();
$this->accessToken = factory(AccessToken::class);
$this->repo_AccessToken = app()->make('AppRepositoriesAccessTokenRepository');
}
public function testFindToken()
{
$model = $this->accessToken->make();
$model->save();
$model_accessToken = $this->repo_AccessToken->findToken($model->id);
$this->assertInstanceOf(IlluminateDatabaseEloquentModel::class, $model);
$this->assertNotNull(true, $model_accessToken);
}
}
Advertisement
Answer
Use this command to run a specific test from your test suite.
JavaScript
phpunit --filter {TestMethodName}
If you want to be more specific about your file then pass the file path as a second argument
JavaScript
phpunit --filter {TestMethodName} {FilePath}
Example:
JavaScript
phpunit --filter testExample path/to/filename.php
Note:
If you have a function named testSave
and another function named testSaveAndDrop
and you pass testSave
to the --filter
like so
JavaScript
phpunit --filter testSave
it will also run testSaveAndDrop
and any other function that starts with testSave*
it is basically a sub-string match. If you want to exclude all other methods then use $
end of string token like so
JavaScript
phpunit --filter '/testSave$/'