Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

patrick_418's avatar

Best practice: Testing Nova resources.

How should Laravel Nova resources be tested? Many of the examples i find online test Nova itself rather than the implementation of the developer.

1; What do i want to test?

  • I don't trust myself when creating a migration, that Nova resources are being updated correctly.
  • Ensuring the right rules are applied to a Nova resource.
  • Ensure i'm able to persist the data ( if this isnt testing Nova itself )
  • Anything else i might be forgetting, ( policies? )

2; In general, how much/far should you test nova?

3; Practical case; Let's say i have a very simple resource called company:

class Company extends Model
{
	protected $table = 'companies';

	protected $fillable = [
        	'name',
        	'active'
    	];
}

And this is my Nova resource:

class Company extends Resource
{
	public static $model = \App\Models\Company::class;


	public function fields(Request $request)
	{
		return [
			ID::make()->sortable(),

			Text::make('name')
                		->rules('required', 'max:100'),

			Boolean::make('active'),

			Boolean::make('non_existing_field'),

			Date::make('created_at')->readonly(),

			HasMany::make('User'),
        ];
    }
}

I can imagine i'd like to make sure that my name rule is correct, and make sure my non existing field is discovered so i can fix this.

At this point i havent really got a clue how to do this (Let alone in a best practice way). An example or/and an explanation would be very welcome and i hope this helps other people who are looking to start testing nova.

Thanks guys.

0 likes
1 reply
bobbybouwmann's avatar
Level 88

Yeah, Nova resources are a bit hard to test in the regular PHPUnit way.

The easiest way to write proper tests for this is by using Laravel Dusk. That is also how Laravel Nova itself is tested. You can assert certain things in the view and assert if actions do the correct thing. You can then verify in the database if everything was correct.

Another solution for example is doing a get request to the API call that is being called underwater for Nova itself and assert the response in there. However, Laravel Nova fires multiple API requests for once view, so you need to be aware of this.

1 like

Please or to participate in this conversation.