logo

How many rows should you create when testing a data grid?

And how should you shape the data?

Joel Clermont
Joel Clermont
2025-12-02

I was recently testing a Livewire component which displayed a typical grid of results. Each row represented a model.

How many records would you create in your test to feel sufficiently confident that the grid was working as expected? And would you just use a factory to create them, or how would you shape the data for those records?

In my case, I decided to create just two records, but the two records had different characteristics.

The first record had only the bare minimum number of fields required to save it to the database. The remaining fields would be null.

The second record had every single field specified.

Having these two varying shapes of records helped me make sure null values would render properly. For example, maybe you chain through a relationship that might not exist, or you have an optional date field that is formatted if present.

On the other hand, without having some completely filled out records, I might miss other logic or rendering bugs that only occur when that field is present. For example, an enum cast or some other Eloquent attribute with logic.

Why only 1 record of each type? Why not more?

In my case, it was sufficient because this particular model didn't have fields that would trigger different business logic.

In other projects, let's say you had a status field which triggered some other business or rendering logic, I might have more records to represent those additional states.

My goal is to have just enough records to feel like I will hit any possible edge case in the Blade logic.

Here to help,

Joel

P.S. Want more free education? Check out our YouTube channel and free books.

Toss a coin in the jar if you found this helpful.
Want a tip like this in your inbox every weekday? Sign up below 👇🏼
email
No spam. Only real-world advice.