Wednesday, June 17, 2015

Sprout approaches when you are adding new features/ modifing the existing features in a legacy application

     The sprout approaches is one of approaches which helps us when we are changing a legacy application and use these approaches with cautious.

Used when:
  1. you do not have much time to get the class under test harness 
  2. these new changes are to be get under test harness
  3. you want to develop these changes/method in test driven development
Types
  1. Sprout Method
  2. Sprout Class
Sprout Method : Steps to implement this type
  1. Identify where you need to make your code change.
  2. If the change can be formulated as a single sequence of statements in one place in a method, write down a call for a new method that will do the work involved and then comment it out.
  3. Determine what local variables you need from the source method, and make them arguments to the call.
  4. Determine whether the sprouted method will need to return values to source method. If so, change the call so that its return value is assigned to a variable.
  5. Develop the sprout method using test-driven development.
  6. Remove the comment in the source method to enable the call.
 Tips to get a new method under test harness
  • If the constructor is having bad dependencies, then try to pass the null values 
  • If passing null values to the constructor does not work, make that method as static.
Sprout Class : This type should be used  when the you can not get the new method under test harness even after the passing null values to the constructor and you can not make the new method as static.
Steps to implement this type as follows.
  1. Identify where you need to make your code change.
  2. If the change can be formulated as a single sequence of statements in one place in a method, think of a good name for a class that could do that work. Afterward, write code that would create an object of that class in that place, and call a method in it that will do the work that you need to do then comment those lines out.
  3. Determine what local variables you need from the source method, and make them arguments to the classes' constructor.
  4. Determine whether the sprouted class will need to return values to the source method. If so,provide a method in the class that will supply those values, and add a call in the source method to receive those values.
  5. Develop the sprout class test first.
  6. Remove the comment in the source method to enable the object creation and calls. 

No comments:

Post a Comment