Creating & Running Tests with Laravel

☞ Azraar Azward
Aug 12 · 3 min read
<?php

namespace
Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;

class ExampleTest extends TestCase
{
/**
* A basic test example.
*
*
@return void
*/
public function testBasicTest()
{
$response = $this->get('/');

$response->assertStatus(200);
}
}
$ ./vendor/bin/phpunit ./tests/Feature/ExampleTest.php
<?php

namespace
Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithFaker;

class ExampleTest extends TestCase
{
/**
* A basic test example.
*
*
@return void
*/
public function testBasicTest()
{
$user = factory(User::class)->create();

$response = $this->actingAs($user)->get(route('home'));

$response->assertStatus(200)->assertViewIs('home')->assertSee('You are logged in!');
}
}

☞ Azraar Azward

Written by

An eager Software Engineer always loving to reach the impossible.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade