JesusValera

The importance of tests in our software

Introduction to unit testing with PHP

 Found a typo? Edit me

Test Methodologies

Test-Last

This is the worst methodology and sadly the most common.

It happens when you type the tests AFTER you wrote the production code.

Pros:

Cons:

Test-First

This methodology is when you type the tests BEFORE you wrote the production code.

Pros:

Cons:

TDD (test-driven development)

tdd

This methodology is when you type the tests BEFORE you wrote the production code BUT you are refactoring the code as long as you are working on them.

First, you wrote the test code getting the red light and ONLY then, you work on the implementation to get the green light. Afterwards, you refactor it and so on.

Cons:

Unit test resources

We use to say “mock” when we want to reference a test double, but there are actually five different types and mock is only one of them.

It can really help you understand what you’re trying to accomplish with your test if you know about what you are doing.

Test doubles

A Test Double is any object that stands in for a real dependency in automated testing. Usually, in PHPUnit, we make test doubles for other classes, but you can also double built-in PHP functions or closures.

The five types of Test Doubles are: