I’m learning to do TDD in practice in small project. I want to create a countdown timer class, how to implement it in TDD(Red, Green, Refactor), and it has the delegate callback as well.
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I am not sure of your exact question, but I think you want to know how you can write tests first for your countdown timer?
If so start with writing one of the primary tests, say Start, Stop, or Reset. These are your action events and will be the ones you invoke first (most likely). Code these tests first and execute them. They should be red because they can’t actually run the countdown timer.
Then add dummy code to one of the functions in your countdown timer. For instance, add the Start() function which starts the countdown timer. Leave the function empty for now. The test should still be red
Now we need to add a way to get the current time remaining. Add a “Remaining” property where we can check the time remaining. Update the test so that it captures this property, starts the timer and then checks the property again to see if it changed. The test should be red still since we have no code to change the property.
Update the start method to kick off your countdown process and update the internals of your countdown timer. Rerun your test now and it should be green since the value is changing.
Now it’s time to refactor. Look through your code and clean things up. Simplify where you can and then reexecute your tests. If all is good everything should be green and you can move on to your next test.
Hope that helps.