<?php

namespace Tests\Feature;

use App\User;
use Illuminate\Support\Facades\DB;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class CategoryTest extends TestCase
{
	private function createUser()
	{
		// Creating an temporal user
		return User::create( [
			'name' => 'Temporal',
			'email' => 'temporal@gmail.com',
			'password' => bcrypt('secret'),
		] );
	}

	/**
	 * A basic test example.
	 *
	 * @depends testCreateUser
	 *
	 * @param User $user
	 *
	 * @return void
	 */
    public function testCreateCategory(User $user)
    {
        $temporal_category = [
            'user_id' => $user->id,
            'name' => 'Temporal Category',
        ];

        $category =  $this->post('api/categories', $temporal_category);
        $category->assertStatus(201);
        $this->assertDatabaseHas('categories', $temporal_category);
    }
}

<?php

namespace Tests\Feature;

use App\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;

class CategoryTest extends TestCase
{
    use DatabaseTransactions;

    /**
	 * A basic test example.
	 *
	 * @return void
	 */
    public function testCreateCategory()
    {
        //$faker = Faker\Factory::create();
        $user = factory(User::class)->create();
        $category = array(
            'user_id' => $user->id,
            'name' => 'Category Temporal'
        );

        $response = $this->post('api/categories', $category);
        $response->assertStatus(201);
        $this->assertDatabaseHas('categories', $category);
    }
}

Add a change to test
Add a change to test
