douzuizhuo0587 2017-08-05 14:09 采纳率: 0%
浏览 38

当我在2个函数中编写API的单元测试时,我得到了NotFoundHttpException

I'm working on Laravel 5.4 and trying to write the unit test to cover my function. But I got a crazy bug. Please have look at my code and help me.

Here is my test file

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);
    }
}

When I try to run command: phpunit I got this error:

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

But when I run separately for each function:

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 functions are the same code. but I got the issue 404: NotFoundHttpException This is the first time I got this issue.

Can anyone help me for this bug?

Many thanks.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 微信会员卡接入微信支付商户号收款
    • ¥15 如何获取烟草零售终端数据
    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?