Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

Two More Tests with TDD

Premium
6 min read

Let's continue our TDD journey. The next feature for the products list will be that the products page loads, and if there are no products, it shows an empty table with the text No products found. If there are products, they are shown in the table. Similar to what we have done already.


Empty Table Test

So, first, the test. Yes, before writing the feature code, remember.

tests/Feature/ProductsTest.php:

class ProductsTest extends TestCase
{
use RefreshDatabase;
 
// ...
 
public function test_homepage_contains_empty_table(): void
{
$user = User::factory()->create();
$response = $this->actingAs($user)->get('/products');
 
$response->assertStatus(200);
$response->assertSee(__('No products found'));
}
}

Now, let's run the test.

The GET request works, and it returns status 200. This part we made in the last lesson. Now, the error is that we don't see the message when the table is empty.

In the Controller, the index method...

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 14 min)

You also get:

54 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

A
angel ✓ Link copied!

Hellooo, Nice course. Can you update the "advanced laravel testing" course link to the new one with laravel 11 (https://laraveldaily.com/course/testing-advanced) ?

M
Modestas ✓ Link copied!

Updated! Thanks for noticing!