Laravel: PHPUnit Testing for Beginners
June 2019 / 1 h 30 min / Laravel 5.8Watch Video About the Course
Course released: June 2019
Course length: 1 h 30 min
Laravel version: 5.8
Automated testing is a crucial part of any long-term IT project. But often developers don't have time for that - budgets and deadlines are tight, and clients want to launch features quickly.
As a result, a lot of developers never start actually testing, because they don't have projects with time/budget to afford this "luxury". Also it seems that PHPUnit and "100% Test Coverage" are really complicated.
In reality, automated testing is pretty simple - and I will prove it to you in this course.
To start testing simple functionality, it's enough to invest a few hours and you will adapt the mindset, with basic examples.
Throughout this course, we will create a mini-application for Products CRUD, and with every page I will show you different details of automated testing:
- Testing that some text is on the page
- Testing that some data is correctly added/updated/deleted
- Testing that correct validation was actually fired
- Testing that only authenticated users access the data
Finally, in the last lesson I will show you a TDD approach to write tests, with test written before the actual application.
Comments from students:
I consider myself a Laravel expert. Work with Laravel for around 7 years, sharing my thoughts on the YouTube channel "Laravel Daily": https://www.youtube.com/c/LaravelDaily
I also have written a Laravel Daily Blog for 5+ years.
StartIntro: WHY do you need to (automatically) test your code? (2:11)
PreviewOur First Test: How PHPUnit works? What is Test and Assertion? (4:45)
StartReal project "Product List": Testing that table is (not) empty (5:45)
StartDatabase Configuration: RefreshDatabase, Phpunit.xml and .env.testing (7:27)
StartBe careful with assertSee: test DATA to avoid false positives (3:07)
StartUnit Tests vs Feature Tests: example of currency converter (9:32)
PreviewFactories: How to create many testing records without loops (6:43)
StartAuth Test: Does user have access to the page? (10:13)
StartAvoid creating the same data: Private methods or setUp() (4:20)
StartTesting roles: only Admin can access creating products (6:49)
StartNew Product: testing that record was saved into database (4:17)
StartEdit Product: Testing correct values in form inputs (3:27)
StartUpdate Product: test if validation error is fired correctly (4:47)
StartDelete Product: test if it's actually removed from database (3:00)
StartTesting file uploads: fake storage driver (4:54)
StartPHPUnit Flags: run only the tests you're interested in (3:16)
StartTest Driven Development: simple TDD example (7:28)