Name: Yoan Ribeiro
Title: Full-Time Learner
Works @ JS-Republic
@yoanribeiro
Yoanribeiro
You make unit test by using TDD but make unit test is not necessary using TDD
when you test a small part of code isolated from the rest.
(e.g. function or class)
Take, the example of a function responsible of returning the number of specific dom elements.
We will use Mocha as test runner
Chai as assertion library
Prepare the case you want to test
Call what you want to test
Verify the behavior, result of what you test
The three parts of every unit test
First test your use case, then implement your use case, refactor and start over until functionality is over.
Write a test
which fails
Refactor by keeping it green
Make the test
pass
Write a unit test which test a case not yet implemented. Obviously, this test will failed !
It's what we want
Write a test
which fails
Refactor by keeping it green
Make the test
pass
Write an implementation which resolve the case that you just test (and the previous test cases) and no more
Write a test
which fails
Refactor by keeping it green
Make the test
pass
Refactor to improve the general implementation by keeping every use case green.
Write a test
which fails
Refactor by keeping it green
Make the test
pass
TDD is nice to increase quality
TDD should not be a dogma
To make unit tests every single time is already good thing