Test: Calculate Total
Implement and test the functionality to calculate the total cost of items in a shopping cart.
1. Write the Failing Test
Test the 'CalculateTotalCost' functionality by adding items to the cart and asserting the expected total cost.
2. Implement a Deliberately Failing Method
In the ShoppingCart class, implement the CalculateTotalCost method to return a wrong value initially.
3. Run the Test and Confirm It Fails
The test should fail, validating its effectiveness.
4. Implement the Correct Method to Pass the Test
Update the CalculateTotalCost method with the correct implementation.
5. Re-run the Test
The test should now pass, confirming the correct implementation.
6. Refactor if Needed
Evaluate the code for possible refactoring.
This approach ensures that each aspect of the functionality is tested and verified, adhering to the TDD principles. The initial failing test (Step 2) confirms that the test is valid and only passes when the correct logic is implemented (Step 4).
Last updated