小编Ste*_*fan的帖子

Laravel单元测试显示完全错误

我正在尝试为我的laravel 5.2项目创建一个测试,该测试将在rest资源控制器中测试注册页面。当我用测试的确切输入手动测试它时,一切正常,但是当我使用它进行测试时,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);
}
}'
Run Code Online (Sandbox Code Playgroud)

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 …
Run Code Online (Sandbox Code Playgroud)

php unit-testing laravel laravel-testing laravel-5.2

5
推荐指数
1
解决办法
634
查看次数