Laravel 5.4上的示例PHPUnit测试失败,带有404

前端之家收集整理的这篇文章主要介绍了Laravel 5.4上的示例PHPUnit测试失败,带有404前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我可以通过link:localhost:8888 / streaming_statistic / public在Laravel 5.4上创建我的项目

我有一个测试:

<?PHP

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ApiTest extends TestCase
{
    public function testBasicTest()
    {
        $response = $this->get('/');

        $response->assertStatus(200);
    }
}

我用命令运行所有测试

./vendor/bin/PHPunit

但结果是:

PHPUnit 5.7.13 by Sebastian Bergmann and contributors.

F                                                                   1 / 1 (100%)

Time: 222 ms,Memory: 12.25MB

There was 1 failure:

1) Tests\Feature\ApiTest::testBasicTest
Expected status code 200 but received 404.
Failed asserting that false is true.

/Applications/MAMP/htdocs/streaming_statistic/vendor/laravel/framework/src/Illuminate/Foundation/Testing/TestResponse.PHP:56
/Applications/MAMP/htdocs/streaming_statistic/tests/Feature/ApiTest.PHP:16

FAILURES!
Tests: 1,Assertions: 1,Failures: 1.

我可以打开这个页面http://localhost:8888/streaming_statistic/public/
我有一条路线:

Route::get('/',function () {
    return view('welcome');
});

我做错了什么?
在laravel中为控制器方法编写测试的正确方法是什么?可能是HTTP测试它不是最好的解决方案吗?

对于测试这个env变量是错误的……
APP_URL=http://127.0.0.1:8888/streaming_statistic/public

我将root web服务器目录更改为streaming_statistic / public和env to

APP_URL=http://127.0.0.1:8888

之后我得到了:

OK (1 test,1 assertion)
原文链接:https://www.f2er.com/laravel/132599.html

猜你在找的Laravel相关文章