Summary of Ep27 - Test Driven Development (TDD) | Laravel API Server
Main Speaker
- Sam
The video discusses Test Driven Development (TDD), a programming methodology that emphasizes writing tests before writing the actual code. The speaker, Sam, explains that TDD helps developers think about the expected behavior of an application upfront, which can significantly reduce bugs in large enterprise applications.
Key Points Covered
- Definition of TDD: TDD involves writing tests that define expected behavior before coding. If the tests pass, the code is considered to meet the defined expectations.
-
Practical Example: Sam demonstrates TDD by creating an arithmetic helper class with functions for addition and subtraction. He outlines the process of writing tests for these functions, including:
- Happy Path Testing: Testing expected behavior, such as adding numbers.
- Sad Path Testing: Testing error handling for non-numeric arguments and ensuring at least one argument is provided.
-
Testing Process:
- The speaker prefers to write all test cases before writing the test code to avoid forgetting any.
- He runs tests using PHPUnit and illustrates how to implement code to pass each test iteratively, emphasizing the importance of minimal code changes to achieve passing tests.
- refactoring: The speaker discusses the need to refactor code after passing tests, particularly to handle additional cases like multiple arguments and type validation.
- Personal Approach: Sam shares his personal preference for defining tests and writing code in a way that may not strictly follow TDD but works for him.
- Key Takeaway: TDD is about writing tests first and developing code to meet those tests, which can be time-consuming but ultimately leads to more reliable code.
Notable Quotes
— 05:24 — « Personally I'm not a big fan of the typical TDD approach that is to write code just to pass one test at a time to me it is not very productive since we need to constantly refactor our code. »
— 07:52 — « Test driven development or TDD for short is the idea of writing tests first and write the code later. »
Category
Technology