Reputation: 2178
I have been given a source code. I have to implement TDD approach to it.
How ever the general approach for TDD is:
Upvotes: 1
Views: 150
Reputation: 14080
You could treat that code base as third party code and write some learning tests for it. Learning tests will allow you to discover the code while building yourself a nice test suite for further developments should you have to modify the code later.
If the legacy code is small enough, you could do that until code coverage gets near a comfortable 90 or 100%.
Upvotes: 0
Reputation:
Don't forget step 0: understand the requirements. What you can do is to discover the requirements, then write the test that demonstrates whether the requirement is satisfied. If it will pass, then great. If it doesn't, you've found a bug. Either way, you've added a regression test.
What you can't do is implement TDD (or any development practice) for code that's already been written: that boat has sailed. What you can do is enable future development on the codebase to benefit from test-driven development practices.
Upvotes: 1