2016-08-08 10 views
9

Użycie polecenia phpunit Laravel przeprowadzi wszystkie testy jednostkowe w naszym projekcie. Jak uruchomić jedno lub kilka testów jednostkowych w Laravel 5.1?Wykonaj tylko jeden test jednostkowy z zestawu testów w języku laravel

Po prostu chcę uruchomić testFindToken z mojego zestawu testów.

<?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); 
    }  
} 

Odpowiedz

16

Użyj tego polecenia, aby uruchomić określony test z zestawu testów.

phpunit --filter {TestMethodName} 

Jeśli chcesz być bardziej szczegółowe na temat pliku, a następnie przekazać ścieżkę pliku jako drugi argument

phpunit --filter {TestMethodName} {FilePath} 

Przykład:

phpunit --filter testExample path/to/filename.php 

Uwaga:

Jeśli masz funkcję o nazwie testSave i anothe Funkcja R nazwany testSaveAndDrop i zdać testSave do --filter jak tak

phpunit --filter testSave 

będzie również uruchomić testSaveAndDrop i wszelkie inne funkcje, które rozpoczyna się testSave*

to jest w zasadzie mecz podciąg. Jeśli chcesz wykluczyć wszystkie inne metody, użyj $ końcówki tokenu, tak jak

phpunit --filter '/testSave$/' 
+1

Świetnie! Dzięki Zayn :) –

Powiązane problemy