Challenge 1: Write a Feature Test — Possible Solution ==================================================================== // tests/Feature/BookDetailTest.php namespace Tests\Feature; use App\Models\Book; use Illuminate\Foundation\Testing\RefreshDatabase; use Tests\TestCase; class BookDetailTest extends TestCase { use RefreshDatabase; public function test_book_detail_returns_200_and_shows_title(): void { $book = Book::factory()->create(['title' => 'The Left Hand of Darkness']); $response = $this->get("/books/{$book->id}"); $response->assertStatus(200); $response->assertSee('The Left Hand of Darkness'); } } WHY THIS WORKS -------------- - use RefreshDatabase; ensures this test (and every other test in the suite that also uses it) runs against a freshly migrated, empty database — the Book created here is guaranteed not to collide with, or leak into, any other test. - Book::factory()->create([...]) both builds a realistic Book instance (using BookFactory's definition() for any fields not explicitly overridden, like price) AND immediately saves it to the database — overriding just the title field means the test can assert on a specific, known value without needing to define every field by hand. - $this->get("/books/{$book->id}") uses the actual generated book's ID in the URL — never a hardcoded ID like /books/1/ — so the test remains correct regardless of what auto-incrementing ID the factory happened to assign. - assertSee() checks that the given text appears somewhere in the rendered HTML response body — a simpler, less brittle check than asserting on the exact full HTML structure, while still confirming the book's actual data made it into the page.