Unit Testing become Test Driven Development. Introduction to the concept of Unit testing with some examples of PHPUnit. Finishing with a Kata TDD (FizzBuzz). Prepared for a class with 3 hours of duration or 4h repeating the Kata.
We may forget corner cases. • We test our code as a whole instead of small parts. • To check if everything works fine takes long time, more as the project grows.
if your code works • A unit test is the best updated documentation and guide to understand your code. • We can add new features checking if the old ones still work. • If features break the unit test will tell us where the error is. • Gives us the confidence to refactor code that we don’t know.
Testing code is also “Production code” • Test for other developers • SOLIDify your tests • One test => One feature • Use less assertions as possible • Love your tests <3
Mock all related dependencies. Use baby steps. 2. Implement ◦ Write the minimum code to make the test pass. Don’t make it beautiful, just pass the test. 3. Green ◦ Run the test to check that everything works fine. 4. Refactor (very important) ◦ Now it’s time to make it beautiful, improve your code. This applies to the test itself too.
For multiples of 3, print “Fizz” instead of the number • For multiples of 5, print “Buzz” instead of the number • For multiple of 3 and 5 print “FizzBuzz” instead of the number • Ex.: 1, 2, Fizz, 4, Buzz, Fizz, … 13, 14, FizzBuzz, 16 Base environment https://github.com/alexgt9/kata-fizzbuzz