This is the red-green-refactor cycle from the Test-Driven Development world.

It helps you:
- Approach problems from a different perspective
- Avoid bugs
- Build more maintainable applications

🧵Keep reading Image
1/6 The red

First, you write a test. You don’t have any code yet, but you know what you want to write.

So you write a test for the most simple use-case.

Something like that: Image
2/6 The green

(Yes, we are doing the calculator example!)

Now it’s time to make this test pass, or in other words, make it green!

In this phrase you should write the minimum amount of code that makes your test green: Image
3/6 In the red again

After that, you may find new requirements or edge-cases for your class.

For example, what happens with division by zero?

You found a new edge-case, so you write a test for it: Image
4/6 In the green again

Of course, you don’t have any code yet that takes care of division by zero, so you should write it: Image
5/6 The refactor

Now everything is green, but during lunch, you read about clean code, and now you hate the divide function.

At this point, you have 100% code coverage meaning the whole class is covered with tests. You’re almost unable to make mistakes! So let’s refactor: Image
6/6 Thank you for reading this!

Today I released a book “Test-Driven APIs with Laravel and Pest” where I cover these topics in great detail.

So far it got only 5-star ratings:
martinjoo.gumroad.com/l/tdd-api-lara…

• • •

Missing some Tweet in this thread? You can try to force a refresh
 

Keep Current with Martin Joo

Martin Joo Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @mmartin_joo

7 Jan
Here are my top 10 #Laravel packages📦

I would immediately DIE without them!

🧵Keep reading
1/11 laravel-query-builder by @spatie_be

With this package, you can build Eloquent queries based on the Request. It can handle things like:

- Filtering
- Sorting
- Including relationships
- Sparse fieldsets Image
2/11 has-many-deep by @staudenmeir

With this package, you can query deep relationships with a single SQL query.

Consider these relationships:
Country → has many → User → has many → Post → has many → Comment Image
Read 12 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal

Or Donate anonymously using crypto!

Ethereum

0xfe58350B80634f60Fa6Dc149a72b4DFbc17D341E copy

Bitcoin

3ATGMxNzCUFzxpMCHL5sWSt4DVtS8UqXpi copy

Thank you for your support!

Follow Us on Twitter!

:(