Creating a Dependency Injection test seam is the most flexible solution long term however there are other ways to introduce test seams.
Im still fairly new to testing but i have found the following useful in some cases as its simple. If your purpose is to just get on and test your class and you can change the classes in involved you can put a different type of test seam in to assist you. This is not great design but its an option especially if you dont want to go with dependency injection yet. 1. you could add 1.a. virtual DataGenerator CreateDataGenerator() to DataConsumer 1.b. call that CreateDataGenerator() instead of the new DataGenerator() 1.c. then create a new TestDataConsumer by inheriting from DataConsumer and overriding that method for your test purpose. This lets you test your DataConsumer and control your generator. Its still not good design but it works as you still have a code with a hard class dependency. On Mar 21, 12:10 am, Josef Semmler <[email protected]> wrote: > Hi there, > > i'm new to rhino and new to mocking - so sorry for propably asking a > stupid question: > > I have code which looks something like this (simplified): > > public class DataGenerator > { > public string GetName() > { > return "My Name"; > } > } > > public class DataConsumer > { > public DataConsumer () {} > > public int GetNameLength ( ) > { > DataGenerator dg = new DataGenerator(); > return dg.GetName().Length; > } > } > > I'd like to create a Unit Test for the "DataConsumer". I'm wondering > if it is possible with Rhino.Mocks to get the "DataGenerator" mocked > somehow - without changing the code (in particular, without making the > local "dg" variable a class variable). > > Thanks for any thoughts! > JS -- 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.
