[英]Laravel unit testing show complete error
I am trying to create a test for my laravel 5.2
project which will test a register page in a rest resource controller. 我正在尝试为我的
laravel 5.2
项目创建一个测试, laravel 5.2
项目将测试其余资源控制器中的注册页面。 When I test it manually with the exact input of my test everything works but when I test it with phpunit
I get redirected to an error page making my page assert fail. 当我用我的测试的确切输入手动测试它一切正常但是当我用
phpunit
测试它时,我被重定向到错误页面使我的页面断言失败。 The error however displays the error of the assert failing and not what is on the error page and thus doesn't show why the test failed. 但是,错误会显示断言失败的错误,而不是错误页面上的错误,因此不会显示测试失败的原因。 How can I see this?
我怎么能看到这个?
Testcase: 测试用例:
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 error: 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.
One way to investigate the error would be to activate error reporting for Illuminate\\Foundation\\Validation\\ValidationException
in your app/Exceptions/Handler.php
. 调查错误的一种方法是在
app/Exceptions/Handler.php
激活Illuminate\\Foundation\\Validation\\ValidationException
错误报告。
protected $dontReport = [
// ValidationException::class,
];
If you run the test again, there should be a stack trace in your log file. 如果再次运行测试,则日志文件中应该有一个堆栈跟踪。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.