[英]Show error of two strings are equal in unit testing
I have created a small Laravel project and I am applying unit testing on my project.我创建了一个小型 Laravel 项目,并且正在对我的项目进行单元测试。 When I fill wrong credentials in function, it doesn't redirect to the login page and shows error on terminal saying Failed asserting that two strings are equal.
当我在函数中填写错误的凭据时,它不会重定向到登录页面并在终端上显示错误,说失败断言两个字符串相等。 Here is my code...
这是我的代码...
$credentials = [
'email' => 'test@gmail.com',
'password' => 'wrongcode'
];
$this->post('/login', $credentials)->assertRedirect('/login');
But when i change assertRedirect('/login')
to assertRedirect('/')
, it works fine但是当我将
assertRedirect('/login')
更改为assertRedirect('/')
,它工作正常
$credentials = [
'email' => 'test1234@gmail.com',
'password' => '98756412'
];
$this->post('/login', $credentials)->assertRedirect('/');
assertRedirect checks two string, one of them is an argument of method, 2nd is redirect path. assertRedirect 检查两个字符串,其中一个是方法的参数,第二个是重定向路径。 Looks like everything works fine.
看起来一切正常。 You write a test, test failed, you have feedback to improve application.
你写了一个测试,测试失败了,你有反馈来改进应用程序。 In that case, the redirect path is different than expected by you.
在这种情况下,重定向路径与您预期的不同。
There should be 2 different methods for an individual scenario like below.对于如下所示的单个场景,应该有 2 种不同的方法。
public function testCorrectCredential() {
$credentials = [
'email' => 'test1234@gmail.com',
'password' => '98756412'
];
$this->post('/login', $credentials)->assertRedirect('/');
}
public function testInCorrectCredential() {
$credentials = [
'email' => 'incorrect@gmail.com',
'password' => '98756412'
];
$this->post('/login', $credentials)->assertRedirect('/incorrect-url');
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.