From the course: Advanced Laravel

Unlock the full course today

Join today to access over 24,800 courses taught by industry experts.

Write database tests

Write database tests - Laravel Tutorial

From the course: Advanced Laravel

Write database tests

- [Instructor] While writing HTTP tests, we have used some database-related utilities like model factories and seeding in our tests. In this video, we'll explore additional techniques provided by Laravel. We'll use the same tests. When we ran this test a while ago, it passed, right? Now let me try running it again, copy this. Sale artisan test filter. Paste the method, and now it fails. We didn't change anything, so I thought it will pass, right? But no, it says the date and time has already been taken. That means when the test ran for the first time, a class was scheduled for that date and time and that row still exists in the testing database table. We won't be able to test multiple times if that happens, right? So Laravel lets us reset the database for each test by using a trait. Scroll up here and say use RefreshDatabase, and that's it. Now every time you run a test, a database is reset. That means none of the…

Contents