https://www.tddbuddy.com/katas/100-doors.html
Config :
-
Set up the node project
npm init -y
-
Install typescript / jest / types for jest / typescript jest translator . As dev dependency's
npm i -D jest typescript @types/jest ts-jest
-
Set up the jest config file :
npx ts-jest config:init
Which will create
jest.config.js
file -
Create a
.tsconfig.json
file with the following command ( to get rid of the error message in the command line while running jest):npx tsc --init
-
Next set up a script to run tests every time there is a change in the code :
"scripts": { "test": "jest --watchAll --verbose" }
-
Copying the
Starter TDD configuration
for any project
1. create a new project : mkdir new-tdd-node-project
2. move all configuration , except node_modules to new project: mv ../tdd2/*.* ./
3. install all node dependencies : npm i
4. run the jest script : npm run test
- Arrange : Get together all the variables needed to conduct the test .
- Act : Execute the 1 thing to be tested.
- Assert : Verify your actual value matches the expected value.
The principles you should keep in mind while writing any test code
- (F)ast : The test should be FAST
- (I)ndependent/Isolated : The test should be independent and self contained ( our test should not depend on external dependencies , and one test should not interfere with other tests , and does not depend on external databases / http requests etc )
- (R)epeatable : Every time the test is executed , the result should be the same [ Deterministic test ]
- Should not have
flickering tests
i.e: Some times pass / other times fail
- Should not have
- (S)elf-Validating : Tests should either
pass
orfail
- (T)horough : Tests should cover all scenarios at the unit level using TDD. Because , as you go up , the tests become less.
- E2E tests are the least ( as they take a lot of time)
- Integration Tests are a bit more (As they take a little less time )
- Unit tests are the most (As they take the least time and can cover all scenarios at the unit level) .
- You are not allowed to write any production code unless it is to make a production code pass
- You are not allowed to write any more of a unit test than is sufficient to fail ; a compilation error is a failure
- You are not allowed to write any production code than is sufficient to pass the one failing unit test