Search This Blog

Wednesday, June 16, 2010

Ship It! - 5.2 Testing Untestable Code

Tell your manager you want to start test driven refactoring. You want to start adding the simple hooks to your application that make it possible (or feasible) to do good automated testing. First, create (or borrow) a test plan for the product. Keep the plan simple at first. Don’t try to make it perfect on your first attempt. Shoot for a simple pass that exercises basic functionality. Second, write an automated test. Make the test go as far as you can. When you get stuck, what’s the least amount you can add to the product’s code to get the test running? Is it just a return code to an existing API or an “id” tag for an HTML field? Don’t try to fix every problem with your first pass. Don’t try to add “id” tags to every page in your product; shoot for the one page you need to get the test passing. If your test plan hits a roadblock, don’t stop. Remove the part of the test plan you can’t test and move on. Remember that you can also add the hard part to your next test plan.

Tip 26: Use test driven refactoring to clean up untestable code

No comments:

Post a Comment