-
Notifications
You must be signed in to change notification settings - Fork 0
Programming
Jason Cheong-Kee-You edited this page Nov 2, 2023
·
5 revisions
-
Pre-test refactor for legacy code: Sprout Method, Sprout Class, Wrap Method, Wrap Class
-
Write test: Arrange, Act, Assert
-
Write code
-
Refactor code
Smell Refactoring Large class Extract Class
Apply Single ResponsibilityLong method Extract Method
Make Composed MethodCode not self-explanatory Rename
Make Composed Method
Apply Ubiquitous Language
Apply Single ResponsibilityDuplication Extract Method
Extract Class -
Refactor test
Smell Refactoring Test method name says "what", not "why" Rename to communicate "why" Multiple asserts in test method 1 assert per test method Long data setup Create Test Data Builders Complicated setup of collaborators Use mocks Fragile shared fixtures No shared fixtures between test classes
- Refactoring
- Test Driven Development
- Domain-Driven Design
- Working Effectively with Legacy Code
- xUnit Test Patterns
- People: Actor, Role
- Places: Place, Outer Place
- Things: Item, Specific Item, Assembly, Part, Container, Content, Group, Member
- Events: Transaction, Composite Transaction, Line Item, Follow-up Transaction
- Generic - Specific
- Actor - Role
- Item - Specific Item
- Composite Transaction - Line Item
- Whole - Part
- Container - Content
- Assembly - Part
- Group - Member
- Outer Place - Place
- Transaction - Specific
- Transaction - Role
- Transaction - Specific Item
- Transaction - Place
- Follow-up Transaction - Transaction
- Line Item - Specific Item
- Write regression test
- Feed in input, have code generate output for assertions
- Test all conditional branches
- Test edge cases
- Minimize number of tests
- Refactor code
- Extract class, makes method extraction easier, because shared state is in member variables
- Extract methods
- Remove "chart junk"
- Seek regularity in code. Make moves to make code more regular.
Message | Query | Command |
---|---|---|
Incoming | Assert return value | Assert public side effects |
Sent to Self | Don't test | Don't test |
Outgoing | Don't test | Use mock |
- 100 lines per class
- 5 lines per method
- 4 parameters per method (each hash parameter counts as 1)
- 1 instance variable per rails view
- 2 class names per rails controller action (business, presenter)