Refactoring by Leveraging Your Tests with C# & xUnit
Deep dive into the Refactor phase of TDD. Learn to spot code smells and apply refactoring techniques using real examples, while keeping tests passing to preserve functionality.
Lessons and practices
Refactor Duplicated Code in the Tests
Refactor Tests using Parameterization
Extract Function: calculateItemCost
Refactor duplication between calculate functions
Refactor Magic Numbers to Constants
Extract user validation logic
Extracting validation into validator classes
Extract data normalization code
Setting our sights on the DataStore
Streamline Parameters with a Parameter Object
Introduce a CoursePolicy parameter object
Re-order parameters for cohesion
Provide defaults for most parameters
Extract StudentGrade Logic
Refactor: MoveMethod CalculateFinalGrade
Eliminate the GradeAnalyzer
Eliminate Feature Envy from the Student
Extract a CartItemCollection
Extract the PriceCalculator class
Extract a DiscountCalculator class
Write Tests for Extracted Classes
Interested in this course? Learn and practice with Cosmo!
Practice is how you turn knowledge into actual skills.