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.
<?php
use Mockery as m;
use App\Models\AccessToken;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class AccessTokenRepositoryTest extends TestCase
{
use WithoutMiddleware;
public function setUp()
{
parent::setUp();
$this->accessToken = factory(AccessToken::class);
$this->repo_AccessToken = app()->make('App\Repositories\AccessTokenRepository');
}
public function testFindToken()
{
$model = $this->accessToken->make();
$model->save();
$model_accessToken = $this->repo_AccessToken->findToken($model->id);
$this->assertInstanceOf(Illuminate\Database\Eloquent\Model::class, $model);
$this->assertNotNull(true, $model_accessToken);
}
}
Running a Single PHPUnit Test Case. To Run a single PHPUnit Test Case on a method within the file: Open your PHPUnit Test Case file in the editor. Place your cursor on the method you wish to test, right-click and select Run As | PHP Unit Test.
Use this command to run a specific test from your test suite.
phpunit --filter {TestMethodName}
If you want to be more specific about your file then pass the file path as a second argument
phpunit --filter {TestMethodName} {FilePath}
Example:
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
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
phpunit --filter '/testSave$/'
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With