# Creating a resource with a test file
By adding the --test flag to themoonshine:resource
command,
you can generate a test file along with a basic test suite:
php artisan moonshine:resource PostResource --test
tests/Feature/PostResourceTest.php
If you are using Pest, you can specify the --pest option
php artisan moonshine:resource PostResource --pest
public function test_index_page_successful(): void{ $response = $this->get( $this->getResource()->indexPageUrl() )->assertSuccessful();}
# Setting up an authenticated user
Although testing MoonShine resources is no different from standard testing of your application and setting up an authenticated user for the request should not be difficult, We'll give an example anyway:
protected function setUp(): void{ parent::setUp(); $user = MoonshineUser::factory()->create(); $this->be($user, 'moonshine');}