Thank you Tim for your response. I'll get the Michael Feathers book. In fact my code needs refactoring before testing it. What about RhinoMocks? Is there any book ? I have "The art of Unit Testing" of Roy Osherove which is good for start but would like if there is a book for more advanced technics.
Thanks. P.S. Sorry for other people to post it in RhinoMocks group. On 16 sep, 15:04, Tim Barcz <[email protected]> wrote: > I would pick up Michael Feather's book *Working Effectively With Legacy Code > ** *he talks in there about some specific examples of how to make code more > testable. If you're not familiar, Michael defines anything without tests > (including code you JUST wrote) as legacy code. > > Is the base class used around the application or is the base class used > solely to add additional behavior (ie. persistence)? One thought I had is > rather than inheritance use composition. Another thought you could do is > the following: > > Before: > > public class BOCars: PersistentObject > { > public bool MethodIWantToTest() > { > // My logic > > baseclassMethodFromPersistantObject(); > > // more logic > } > > } > > After:public class BOCars: PersistentObject > { > public bool MethodIWantToTest() > { > // My logic > > WrapperMethod() > > // more logic > } > > public virtual WrapperMethod() > { > baseclassMethodFromPersistantObject(); > > } > > } > > Functionally everything works the same but now you have a hook that you can > override. > > Tim > > > > > > On Wed, Sep 16, 2009 at 7:20 AM, TJA <[email protected]> wrote: > > > Hello, > > > I have a question that is not directly related to RhinoMocks so sorry > > if I bother you with that. I was asked to refactor and implement unit > > tests in a legacy code that was developed without any unit tests. I > > work with NUnit and RhinoMocks. > > > The first problem I was faced to is that all fonctionals layers in a > > code are mixes. Business Objects deal with persistance, GUI deals with > > persistance end busines object, busines logic in GUI, data > > manipulation in Business objects and son on. ONE BIG MESS. The most > > impressive is inheritance on several levels. So what's the point. > > > In my persistance layer I have objects that's deals with data. I don't > > want to test it. > > My each Business objects inheritate directly or indirectly from a > > PersistentObject. > > > I need to test a logic in my business objects that inheritate from my > > persistance layer. > > > For exemple: > > > public class BOCars: PersistentObject > > { > > public bool MethodIWantToTest() > > { > > // My logic > > > baseclassMethodFromPersistantObject(); > > > // more logic > > } > > } > > > I would like to remove dependence from PersistentObject to test my > > logic in "MethodIWantToTest()". What's the best way to do it using > > RhinoMocks. Thanks for your advaice and help. > > > TJA > > -- > Tim Barcz > Microsoft > ASPInsiderhttp://timbarcz.devlicio.ushttp://www.twitter.com/timbarcz- Masquer > le texte des messages précédents - > > - Afficher le texte des messages précédents - --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino.Mocks" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/rhinomocks?hl=en -~----------~----~----~----~------~----~------~--~---
