Thanks. I knew that tests should be isolated, but wasn't sure whether mocks should or should not be reused as in each test precondition for running test is existence of mock (instead of real) object (same mock is quite OK) but as you said, that wouldn't be complete isolation which we should strive to.
Once again, thanks for your suggestions. On Nov 19, 5:16 pm, Patrick Steele <[email protected]> wrote: > Ok, fair enough (although this is usually the time when I say you > should be looking for a new job with a better company that values the > input of its developers...) > > Back to the original question: Don't re-use a mock object across > multiple tests. Your tests should be running totally in isolation and > if a single mock is used across multiple tests, your tests aren't > isolated (side effects of operations in one test could affect the > results of another test). And I can almost guarantee you that at some > point in the future, someone will need something slightly different > with that mock, they'll change it for their test and every other test > in the class will break. > > Just create the new mock using the code you posted at the beginning of > each test. > > --- > Patrick Steelehttp://weblogs.asp.net/psteele > > On Fri, Nov 19, 2010 at 3:36 AM, rssole <[email protected]> wrote: > > Unfortunately, it is not up to me it is (more or less) matter of > > politics and this particular environment, > > where on build server as part of CI where tests are also run, there > > also 3.5 is not available. > > But that is completely another story... > > > On Nov 18, 5:55 pm, Patrick Steele <[email protected]> wrote: > >> You could make things easier by having your unit tests written for > >> .NET 3.5, but your application code can still target 2.0. I did this > >> a lot when the company I was working for was slow to push 3.5 out to > >> the users. Devs had it on their machines (and we're the only ones > >> that ran the unit tests), so we used Rhino.Mocks + .NET 3.5 in the > >> unit tests. > > >> --- > >> Patrick Steelehttp://weblogs.asp.net/psteele > > >> On Thu, Nov 18, 2010 at 11:46 AM, rssole <[email protected]> wrote: > >> > Perhaps someone will wonder why using full static invocation syntax > >> > instead of extensions, delegates instead of lambdas etc. > >> > well I am refactoring and adding unit tests to some old .net 2.0 (c# > >> > 2.0) project where extensions and other c# 3.0 stuff is out of reach :) > > >> > -- > >> > 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 > >> > athttp://groups.google.com/group/rhinomocks?hl=en. > > > -- > > 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 > > athttp://groups.google.com/group/rhinomocks?hl=en. -- 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.
