I would not....you're never disposing it. What I would do (in order) if one is not available as an option go to the next)
- Get rid of statics, inject in "logProvider" instance using Windsor or StructureMap with a static lifestyle, more testable with same fundamental idea of one object serving everyone - Create a public static method on LogProvider named ClearState() which resets the shared state back to whatever it needs to be. This method would only be there for testing purposes - If creating a public is a problem, then create an interanl method and make internals visible to your test assembly so that you can call it from your test to reset any stored state That help? On Thu, Nov 12, 2009 at 9:24 AM, tom308 <[email protected]> wrote: > > Hey Alex! > thanks for the answer, but LogProvider is indeed a singleton\static > class... > should i implement a IDisposable for it - just for testing? > > On Nov 12, 5:17 pm, Alex McMahon <[email protected]> wrote: > > I think Tim is suggesting something within your code is where there is a > > state problem. So the answer to "what can I do to prevent this" is to > look > > through the classes you're testing and make sure that multiple instances > of > > the class are truly independent from each other. i.e. there are no > statics > > or singletons that will be shared among multiple instances. LogProvider > does > > look like a sensible place to start > > > > 2009/11/12 tom308 <[email protected]> > > > > > > > > > you are right, something is the mocked instance... > > > > > but what can i do to prevent this ? > > > > > On Nov 12, 4:35 pm, Tim Barcz <[email protected]> wrote: > > > > Without seeing LogProvider, LogMethod1, LogMethod2, LogMethod3 I am > > > guessing > > > > you have saved state problems which is probably coming from use of > > > > LogProvider (static class). > > > > > > *something* is getting saved from execution to execution. > > > > > > Tim > > > > > > On Thu, Nov 12, 2009 at 8:30 AM, tom308 <[email protected]> wrote: > > > > > > > sorry - always the first one is successful and all other are > > > > > failing.... > > > > > > > On Nov 12, 4:29 pm, tom308 <[email protected]> wrote: > > > > > > let me just point that running order didn't change anything > (always > > > > > > the first one is failing) > > > > > > also i tried to call log.BackToRecord(); at the end of each test > > > > > > method - and :-( it didn't help... > > > > > > > > can anyone see the problem ? > > > > > > > > On Nov 12, 9:36 am, tom308 <[email protected]> wrote: > > > > > > > > > Hey Tim, > > > > > > > of course i can: > > > > > > > > > [TestCleanup()] > > > > > > > public void MyTestCleanup() > > > > > > > { > > > > > > > LogManager.Shutdown(); > > > > > > > } > > > > > > > > > #endregion > > > > > > > > > [TestMethod] > > > > > > > public void TestBasicLogMethod() > > > > > > > { > > > > > > > using (Logger log = > > > MockRepository.GenerateMock<Logger> > > > > > > > (null, null)) > > > > > > > { > > > > > > > LogProvider.c_logger = log; > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Debug, > > > > > > > "LogTest.AOPTests", "LogMethod", "OnEntry")); > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Debug, > > > > > > > "LogTest.AOPTests", "LogMethod", "OnExit")); > > > > > > > > > LogMethod(); > > > > > > > log.VerifyAllExpectations(); > > > > > > > } > > > > > > > } > > > > > > > > > [TestMethod] > > > > > > > public void TestLogMethodForCategory() > > > > > > > { > > > > > > > using (Logger log = > > > MockRepository.GenerateMock<Logger> > > > > > > > (null, null)) > > > > > > > { > > > > > > > LogProvider.c_logger = log; > > > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Debug, > > > > > > > LogCategories.LogFile | LogCategories.EventLog, > "LogTest.AOPTests", > > > > > > > "LogMethod2", "OnEntry")); > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Debug, > > > > > > > LogCategories.LogFile | LogCategories.EventLog, > "LogTest.AOPTests", > > > > > > > "LogMethod2", "OnExit")); > > > > > > > > > LogMethod2(); > > > > > > > > > log.VerifyAllExpectations(); > > > > > > > } > > > > > > > } > > > > > > > > > [TestMethod] > > > > > > > public void TestLogMethodForSeverity() > > > > > > > { > > > > > > > using (Logger log = > > > MockRepository.GenerateMock<Logger> > > > > > > > (null, null)) > > > > > > > { > > > > > > > LogProvider.c_logger = log; > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Warning, > > > > > > > "LogTest.AOPTests", "LogMethod3", "OnEntry")); > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Warning, > > > > > > > "LogTest.AOPTests", "LogMethod3", "OnExit")); > > > > > > > > > LogMethod3(); > > > > > > > > > log.VerifyAllExpectations(); > > > > > > > } > > > > > > > } > > > > > > > > > On Nov 12, 4:43 am, Tim Barcz <[email protected]> wrote: > > > > > > > > > > Can you post all of the code here? > > > > > > > > > > On Wed, Nov 11, 2009 at 8:57 AM, tom308 <[email protected] > > > > > wrote: > > > > > > > > > > > Hi all! > > > > > > > > > i am new to TDD & Mocks (but very enthusiastic about it). > > > > > > > > > i am using MSTest & Rhino mock 3.5. > > > > > > > > > testing are OK when running each one separately, but when > > > running > > > > > > > > > entire TestSet, the first one is OK but all other are > failing. > > > > > > > > > My hunch is that i am holding the mocked object between > tests, > > > and > > > > > > > > > causing the problem (i saw that it is same object). > > > > > > > > > i also tried to use a repository instance insted of the > static > > > one, > > > > > > > > > but it didn't help. > > > > > > > > > can someone help ? > > > > > > > > > > > my tests are all from the same template: > > > > > > > > > > > [TestMethod] > > > > > > > > > public void TestBasicLogMethod() > > > > > > > > > { > > > > > > > > > using (Logger log = > > > MockRepository.GenerateMock<Logger> > > > > > > > > > (null, null)) > > > > > > > > > { > > > > > > > > > //set the instance into the logProvider > private > > > > > static > > > > > > > > > logger > > > > > > > > > LogProvider.c_logger = log; > > > > > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Debug, > > > > > > > > > "LogTest.AOPTests", "LogMethod", "OnEntry")); > > > > > > > > > log.Expect(l => > l.WriteToLog(LogSeverity.Debug, > > > > > > > > > "LogTest.AOPTests", "LogMethod", "OnExit")); > > > > > > > > > > > LogMethod(); > > > > > > > > > log.VerifyAllExpectations(); > > > > > > > > > } > > > > > > > > > } > > > > > > > > > > -- > > > > > > > > Tim Barcz > > > > > > > > Microsoft C# MVP > > > > > > > > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp:// > > > > >www.twitter.com/timbarcz > > > > > > -- > > > > Tim Barcz > > > > Microsoft C# MVP > > > > Microsoft ASPInsiderhttp://timbarcz.devlicio.ushttp:// > > >www.twitter.com/timbarcz > > > -- Tim Barcz Microsoft C# MVP Microsoft ASPInsider http://timbarcz.devlicio.us http://www.twitter.com/timbarcz --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
