Skip to main content

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

Read more here

TDD Approach: Simple Example

Premium
4 min read

Until now, we have been writing tests on top of existing Laravel code. We haven't touched a different (opposite) approach called TDD, Test Driven Development. So let's briefly cover it in this final section of the course.


The TDD Approach

In general, the difference is in mindset and in thinking, and in the order of how you do things.

Until now, we have been working in this order:

  • Write the feature code
  • Write the test for features
  • Launch the tests
  • If they fail, fix the feature code and relaunch tests

TDD approach is the opposite:

  • You write tests first
  • Then they fail (intentionally)
  • And then you write the code for features, fixing the test errors
  • Launch the tests again
  • They fail with different errors
  • You write more code for features
  • ... Repeat until the tests succeed

For the example, we will write a couple of the same tests we did already for a product CRUD, but with a TDD approach.


The Practical Example

So, we have a fresh Laravel project. The first feature we will work on is a products list, which...

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

No comments yet…