From: <rdr...@ar...> - 2007-09-11 21:50:18
|
That would be a bahavior which would fix my "problem". Maybe enable a flag in the mockery which defines the "search order" for the= expectations? I would find this behavior much more logical then the other way around. Wit= hout it i have no way to override something i setup once without resulting = to "trickery" (e.g. defining something that i consider a stub to be an expe= ct.once so i can "remove" it with the exact call) =20 So instead of having my generic setup which creates everything thats not im= portant for my test "outside" the test function, and only setting one expec= tation i am actually currently testing inside of my test. And usually this= leads to a buch of helper setup functions, which usually only differ in on= e line, and its not trivial to refactor the other N lines out... Since the = other n-1 functions would all differ in one different line... Also i want to avoid and "logic" in my tests/setups... so a function with a= flag to skip one of those lines also leaves a bad feeling...=20 Anyway... short conclusion: 2 Thumbs up for a flag that defines the search = direction ;) ----- Original Nachricht ---- Von: Nat Pryce <nat...@gm...> An: NMock2 Development Discussion <nmo...@li...= > Datum: 11.09.2007 21:31 Betreff: Re: [NMock2-Dev] Feature Request: "Stub" should have alower =09prioritythen "Expect" > JMock used to check expectations in reverse order so you could set up > some default expectations (stubs usually) and then override them in > individual tests. However, it was so confusing to users that we > removed the feature and just check for expectation matches in the > order that they are defined. >=20 > We found that tests were far more readable if set-up was factored out > into well-named methods called at the start of tests as appropriate > than to define expectations in the SetUp method. >=20 > --Nat >=20 > On 11/09/2007, Steve Mitcham <Ste...@ty...> wrote: > > It's not a matter of priority, the design philosophy is such that NMock= is > expecting either a Stub or an Expectation, but not both. Stub is just > another expectation internally, so if it is first in the list it will mat= ch > all comers. > > > > I could see having an explicit > Expect.Once.On(foo).ReplacingExistingExpectations.SetProperty("Id"); > > > > Which could find and clear all the existing expectations and replace it > for that test case; however, I don't think I'd want to add in an implicit > 'override' behavior between expectations. > > > > That's my opinion of course, if anyone else wants to chime in on this, > please do. > > > > Nat, if you see this can you comment about the original nmock behavior = for > this case, were you able to set up a default and then override it for > specific tests? > > > > -----Original Message----- > > From: nmo...@li... > [mailto:nmo...@li...] On Behalf Of Heiko > Hatzfeld > > Sent: Tuesday, September 11, 2007 9:07 AM > > To: NMock2 Development Discussion > > Subject: Re: [NMock2-Dev] Feature Request: "Stub" should have alower > prioritythen "Expect" > > > > Hello... > > > > Lets ignore the more complicated event code for a second, and get to th= e > "real problem" 1st... > > > > IDbObject foo =3D _mocks.NewMock<IDbObject>(); > > Stub.On(foo).SetProperty("Id"); > > Expect.Once.On(foo).SetProperty("Id"); > > foo.Id =3D 123; > > _mocks.Verify.......; > > > > Say i have an Interface I want to mock. I know during my tests of anoth= er > class, there will be a buch of (generally unimportant) > > method calls that must be "stub"ed so the test in general can run... > > > > But the stubs are not important, they just need to be there.. > > Example i supply a ILog mock which only has a method "Log" > > > > Now in most tests i dont care what will be logged... But on some i need= to > make sure the right message is passed into the logger... > > > > Now i need to override the Log stub and supply an expect.once with a > certain message... now the logger interface might be simple... But if you= do > the same to a fairly complex view, then you need to stub all events etc s= o > the test can work. > > > > So back to the logger... My expection wont be fullfilled if i have defi= ned > a stub before the expection. the stub definition will swallow all calls t= o > Log() and the expection will never catch the "crutial" Log("SH..!!! bette= r > call someone NOW!") > > > > The exections and stubs have not been setup within an > > using (mocks.Ordered) > > {} > > > > block, so i think the expections should have a higher priority priority > then the stubs... After all there is a way to define a strict order. > > > > I can post a full version of my event code if that is still requiered. = But > I dont want to go into a to much detail, since I see the problem as a mor= e > general one. I do have a workaround that works with my event code, but i > think its a hack ;) > > > > > > > > -------- Original-Nachricht -------- > > > Datum: Tue, 11 Sep 2007 07:58:06 -0500 > > > Von: "Steve Mitcham" <Ste...@ty...> > > > An: "NMock2 Development Discussion" > <nmo...@li...> > > > Betreff: Re: [NMock2-Dev] Feature Request: "Stub" should have a lower > prioritythen "Expect" > > > > > Can you give a more complete example of what you are trying to > accomplish? > > > In your sample, you could use Expect.AtLeastOnce as the expectation = to > > > achieve the same effect. > > > > > > I'm also not following your event code example. It appears that you a= re > > > only exercising the mocked view and nothing of a controller class is > apparent > > > in your sample. You need to give a better example here as well for m= e > to > > > determine what it is you are trying to accomplish. > > > > > > I will say that in the current code drop there is some new event > handling > > > code that may suit your needs, so you can write the following (the > sample > > > is from the acceptance test) > > > > > > listenerMessage =3D null; > > > Mockery mocks =3D new Mockery(); > > > Announcer announcer =3D (Announcer) > mocks.NewMock(typeof(Announcer)); > > > > > > Expect.Once.On(announcer).EventAdd("Listeners", > Is.Anything); > > > > > > announcer.Listeners +=3D new > Listener(DummyListener); > > > > > > Fire.Event("Listeners").On(announcer).With("Tes= t > Message"); > > > > > > This might help to serve your purpose. > > > > > > -----Original Message----- > > > From: nmo...@li... > > > [mailto:nmo...@li...] On Behalf Of Hei= ko > Hatzfeld > > > Sent: Tuesday, September 11, 2007 6:09 AM > > > To: nmo...@li... > > > Subject: [NMock2-Dev] Feature Request: "Stub" should have a lower > > > prioritythen "Expect" > > > > > > Hello... > > > > > > This is my first post and I already got some complains.. I know its a > > > great start, but here we go... > > > > > > Giving this code: > > > > > > > > > IDbObject foo =3D _mocks.NewMock<IDbObject>(); > > > Stub.On(foo).SetProperty("Id"); > > > Expect.Once.On(foo).SetProperty("Id"); > > > foo.Id =3D 123; > > > _mocks.Verify.......; > > > > > > It will generate an exception. The reason is that the above code will > not > > > satisfy my expection, since the stub which was defined 1st, will catc= h > the > > > assignment and so the expection will never be reached. > > > > > > I think that an expection is much more important then a stub (Which i= s > > > kinda a "Fallback" only). > > > > > > For example... I want to test a controller for a view, and Verify tha= t > the > > > events are propperly setup and processed... > > > > > > I cannot create an implicit setup for the view (which creates the vie= w > and > > > stubs all events), and then attach a real expection onto the view, th= at > > > will allow me to sneak a mockEvent in, so i can fire it from the > outside, and > > > verify that the controler does its work. > > > > > > I currently need to declare an implicit setup, which defines > expections, > > > since those can be removed by adding a "fake" Handler on the Mock e.g= .: > > > > > > //Inside CreateViewAndSetupBasicEvents Function > > > Expect.Once.On(mockedView).EventAdd("Save", Is.Anything); > > > > > > //Inside my "real" test function... > > > mockedView.Save +=3D null; > > > Expect.Once.On(mockedView).EventAdd("Save", Is.Anything) > > > .Will(MockEvent.Hookup(mockevent)); > > > mockEvent.Raise(); > > > > > > > > > Hope this makes sense.... > > > > > > I know i could "fix" it, by creating the view 1st and then adding the > > > expections, and THEN finally adding all the stubs... But i kinda got > attached > > > to my setup functions so i can create and setup a basic mock with one > > > call... Without that I would have to move the creation of the mock > around, and I > > > feel like i am "loosing" some clarity in my test, if I move to much > into > > > the "general" setup method. > > > > > > > > > -- > > > Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! > > > Ideal f=FCr Modem und ISDN: http://www.gmx.net/de/go/smartsurfer > > > > > > > ------------------------------------------------------------------------- > > > This SF.net email is sponsored by: Microsoft > > > Defy all challenges. Microsoft(R) Visual Studio 2005. > > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > _______________________________________________ > > > NMock-two-dev mailing list > > > NMo...@li... > > > https://lists.sourceforge.net/lists/listinfo/nmock-two-dev > > > > > > > ------------------------------------------------------------------------- > > > This SF.net email is sponsored by: Microsoft > > > Defy all challenges. Microsoft(R) Visual Studio 2005. > > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > > _______________________________________________ > > > NMock-two-dev mailing list > > > NMo...@li... > > > https://lists.sourceforge.net/lists/listinfo/nmock-two-dev > > > > -- > > Ist Ihr Browser Vista-kompatibel? Jetzt die neuesten > > Browser-Versionen downloaden: http://www.gmx.net/de/go/browser > > > > -----------------------------------------------------------------------= -- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2005. > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > _______________________________________________ > > NMock-two-dev mailing list > > NMo...@li... > > https://lists.sourceforge.net/lists/listinfo/nmock-two-dev > > > > -----------------------------------------------------------------------= -- > > This SF.net email is sponsored by: Microsoft > > Defy all challenges. Microsoft(R) Visual Studio 2005. > > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > > _______________________________________________ > > NMock-two-dev mailing list > > NMo...@li... > > https://lists.sourceforge.net/lists/listinfo/nmock-two-dev > > >=20 > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Microsoft > Defy all challenges. Microsoft(R) Visual Studio 2005. > http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/ > _______________________________________________ > NMock-two-dev mailing list > NMo...@li... > https://lists.sourceforge.net/lists/listinfo/nmock-two-dev > |