Fisrst, think about spec, get one test case from spec. (Think: what are the example input and output?)
Spec:
[ square(x) ]
Test Case:
[ square(2) -> 4 ] #Test 1
[ square(-1) -> 1 ] #Test 2
- Write test name
- Put in a comment, describe test case (Given, When, Then)
- Write code just enough for test to fail
- Implement Code
- Run test to pass
- Make sure your test can fail for the right reason
[App] ----- [X] -----> [Console.log()] (Prod.)
Int. | Ext.
|
--------> [Mock]
Collect & test (Unit Test.)
main() -> console.log("hello world")
main(writer) -> writer.log("hello world")
writer #1 -> console.log
writer #2 -> collect, assert