2017-02-12 4 views
3

실패 내가 할 수있는 링크에서 Laravel 5.4에 내 프로젝트 : 로컬 호스트 : 8888/streaming_statistic/공공예 phpunit을 테스트 404

나는 시험이 있습니다

<?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. 
내가 뭘 잘못

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

: 617,451,515,

나는이 경로가이 페이지 http://localhost:8888/streaming_statistic/public/ 를 열 수 있습니까? laravel에서 제어기 메소드에 대한 테스트를 작성하는 올바른 방법은 무엇입니까? HTTP 테스트가 최선의 해결책이 아닐 수도 있습니다. 이 ENV 변수가 잘못 시험

+2

테스트를 위해 올바른 URL과 포트를 설정해야합니다. –

+0

어디서 구성 할 수 있습니까? –

+0

APP_URL = http : //127.0.0.1 : 8888/streaming_statistic/public -이 env 변수가 잘못되었습니다 ... 루트 디렉토리를 streaming_statistic/public으로 변경하고 env를 APP_URL = http : //127.0.0.1 : 8888 - 그리고 OK (1 테스트, 1 주장)! –

답변

6

...

APP_URL=http://127.0.0.1:8888/streaming_statistic/public 

나는 내가 가진 그 후

APP_URL=http://127.0.0.1:8888 

에/streaming_statistic 공공 및 ENV에 루트 웹 서버의 디렉토리를 변경 :

OK (1 test, 1 assertion) 
+0

테스트가 실제로 통과하는 경우 유효성을 검사 할 수 있습니다. 127.0.0.1:8888에 모든 디렉토리 목록이 표시되고 실제로 애플리케이션에 도달하지 않았을 수 있습니다. –