Clean Code
Episode 20
This episode talks about more in-depth on how to keep test clean.
- Anatomy of a Test
- Four Phases of test function. 4 As of Test: Arrange, Act, Assert, Annihilate
- Arrange:Act:Assert, Build:Operate:Check, Given:When:Then
- Arrange: Set the test to the environment to run the test. Create test fixture.
- Act: Call the function we want to act upon.
- Assert: Check the expectation.
- Annihilate: Put the test environment back to the original state.
- The Arrange
- Drive the test to the state (test fixture) it needs for testing
- Transient Fresh – create and destroy around every test
- Persistent Fresh – allow to exist between test, initial around every test
- Persistent Shared – allow to exist between test, allow some states to carry over to other test
- Setup Struggle
- What happen if setup grows?
- Test Hierarchy
- Test group into Hierarchy so setup only specified in those test needed
- Clean Composition
- Action is the thing that you are testing
- It is a good idea to put two or more actions into an utility function so the test looks like testing one actions
- The Assertion
- Test is a boolean operation
- Single Action follow by Single Assertion
- More than one assertion, then composition it into one well name assertion.
- Conclusion
- References
- xUnit Test Patterns, Gerard Meszaros