我正在研究Laravel 5.4并尝试编写单元测试以涵盖我的功能。 但是我遇到了一个疯狂的错误。请查看我的代码并帮助我。
这是我的测试文件
class UserControllerTest extends TestCase
{
use DatabaseTransactions;
protected $isCreateToken = true;
public function testViewAccountDetailWithFieldsOK()
{
$this->get('/v1.0/me');
$this->assertResponseStatus(200);
}
public function testViewAccountDetailOK()
{
$this->get('/v1.0/me');
$this->assertResponseStatus(200);
}
}
当我尝试运行命令时:phpunit
我收到了这个错误:
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
.F 2 / 2 (100%)
Time: 710 ms, Memory: 14.00MB
There was 1 failure:
1) Tests\Controller\Api\UserControllerTest::testViewAccountDetailOK
Expected status code 200, got 404.
Failed asserting that 404 matches expected 200.
/Users/johnnguyen/Workspace/Laravel/mobile/vendor/laravel/browser-kit-testing/src/Concerns/MakesHttpRequests.php:744
/Users/johnnguyen/Workspace/Laravel/mobile/tests/Controller/Api/UserControllerTest.php:24
/Users/johnnguyen/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:186
/Users/johnnguyen/.composer/vendor/phpunit/phpunit/src/TextUI/Command.php:116
但是当我为每个功能单独运行时:
John-Nguyen:mobile johnnguyen$ phpunit --filter=testViewAccountDetailOK
PHPUnit 5.7.21 by Sebastian Bergmann and contributors.
. 1 / 1 (100%)
Time: 591 ms, Memory: 14.00MB
OK (1 test, 2 assertions)
2个功能是相同的代码。
但是我遇到了问题404: NotFoundHttpException
这是我第一次遇到这个问题。
任何人都可以帮我解决这个错误吗?
非常感谢。