[英]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.