使用 phpunit
命令 Laravel 将运行我们项目中的所有单元测试。
如何在 Laravel 5.1
中运行一个或特定的单元测试?
我只想从我的测试套件中运行 testFindToken
。
<?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);
}
}
最佳答案
使用此命令从您的测试套件运行特定测试。
phpunit --filter {TestMethodName}
如果您想更具体地说明您的文件,请将文件路径作为第二个参数传递
phpunit --filter {TestMethodName} {FilePath}
示例:
phpunit --filter testExample path/to/filename.php
注意:
如果您有一个名为 testSave
的函数和另一个名为 testSaveAndDrop
的函数,并且您将 testSave
传递给 --filter
像这样
phpunit --filter testSave
它还会运行 testSaveAndDrop
和任何其他以 testSave*
开头的函数
它基本上是一个子字符串匹配。如果您想排除所有其他方法,请像这样使用 $
end of string token
phpunit --filter '/testSave$/'
关于php - 在 laravel 的测试套件中只运行一个单元测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38821326/