簡體   English   中英

Laravel單元測試顯示完整錯誤

[英]Laravel unit testing show complete error

我正在嘗試為我的laravel 5.2項目創建一個測試, laravel 5.2項目將測試其余資源控制器中的注冊頁面。 當我用我的測試的確切輸入手動測試它一切正常但是當我用phpunit測試它時,我被重定向到錯誤頁面使我的頁面斷言失敗。 但是,錯誤會顯示斷言失敗的錯誤,而不是錯誤頁面上的錯誤,因此不會顯示測試失敗的原因。 我怎么能看到這個?

測試用例:

class registerTest extends TestCase
{
use WithoutMiddleware;

public function testRegisterCompanyCorrectly()
{
    $this->actAsAdmin();
    $this->visit('/Companies/create')
        ->type('testCompany', 'CName')
        ->type('www.testCompany.com', 'CUrl')
        ->type('testManager@gmail.com', 'Mail')
        ->type('John Doe', 'Name')
        ->type('Keith Richards', 'Password')
        ->type('Keith Richards', 'CPassword')
        ->press('Registreren')
        ->seePageIs('/Companies/3')
        ;
}

private function actAsAdmin()
{
    $user = User::find(1);
    $this->actingAs($user);
}
}'

phpunit 錯誤:

There was 1 failure:

1) registerTest::testRegisterCompanyCorrectly
Did not land on expected page [http://localhost/Companies/3].

Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'http://localhost/Companies/3'
+'http://localhost/Companies'

C:\Users\Stefan\Documents\producten\Applicatie\vendor\laravel\framework\src\Illuminate\Foundation\Testing\Concerns\InteractsWithPages.php:170
C:\Users\Stefan\Documents\producten\Applicatie\tests\registerTest.php:34
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:176
C:\xampp\php\pear\PHPUnit\TextUI\Command.php:129

FAILURES!
Tests: 5, Assertions: 14, Failures: 1.

調查錯誤的一種方法是在app/Exceptions/Handler.php激活Illuminate\\Foundation\\Validation\\ValidationException錯誤報告。

protected $dontReport = [
    // ValidationException::class,
];

如果再次運行測試,則日志文件中應該有一個堆棧跟蹤。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM