Skip to content

Instantly share code, notes, and snippets.

@bay007
Created August 3, 2020 00:43
Show Gist options
  • Save bay007/5455c994c597f570a0ec26f1e5ed257e to your computer and use it in GitHub Desktop.
Save bay007/5455c994c597f570a0ec26f1e5ed257e to your computer and use it in GitHub Desktop.
## TDD good habits manifesto
#### (principles)
- tests should test one thing only
- test one logical assertion
- don't mix assertions of state and collaboration in the same test
- modifications of production code should only break related test cases
- each test should be self-contained, including data
- ensure tests are independent of each other
- don't refactor with a failing test
- organise your unit test projects to reflect your production code
- keep your tests and production code separate
- do not use production data and code to test production code
- if your tests are difficult to write or maintain, consider changing the design
#### (red phase)
- create more specific tests to drive a more generic solution (Triangulate)
- give your tests meaningful names (behaviour / goal-oriented) that reflect your production system
- write the assertion first and work backwards
- see the test fail for the right reason
- ensure you have meaningful feedback from failing tests
- Organize your test in Arrange, Act and Assert blocks
- Arrange (aka Given) – all necessary preconditions and inputs.
- Act (aka When) – on the object or method under test.
- Assert (aka Then) – that the expected results have occurred.
#### (green phase)
- write the simplest code to pass the test
- write any code that makes you get to the refactor phase quicker
- it is okay to write any code that you might improve at a later stage
- consider using Transformation Priority Premises to evolve your code
#### (refactor phase)
- refactor aggressively and constantly
- treat tests as first class code
- use the IDE to refactor quickly and safely
- refactor production and test code independently (except changing public interfaces)
- Use the Rule of 3 to tackle duplication
- Code can be copied once, but when the same code is used three times, it should be refactored/extracted
- Remember that duplication is cheaper than the wrong abstractions
![MindMap](TDDManifesto.png)
<hr/>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment