Hi,
has anybody ever mocked/replaced a class during a test to test code containing something like: [...] AClass doSomething. [...] Perhaps an approach like Mock mockClass: AClass while: [:mock | "testcode here" ] Regards, Steffen _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Steffen,
Here's one way of doing this, >>setUp super setUp. MyClass become: MyFakeClass. >>tearDown MyClass become: MyFakeClass. super tearDown. Note, #tearDown isn't a typo, you want the exact same statement to flip the references back. Or, Behaviour>>mock: cls while: block self become: cls. ^[block cull: self] ensure: [self become: cls]. Set mock: IdentitySet while: [:cls | cls name] "#IdentitySet" HTH, -Boris -----Original Message----- From: [hidden email] [mailto:[hidden email]] On Behalf Of Steffen Märcker Sent: Monday, July 04, 2011 5:07 AM To: vwnc Subject: [vwnc] Mocking/replacing a Class Hi, has anybody ever mocked/replaced a class during a test to test code containing something like: [...] AClass doSomething. [...] Perhaps an approach like Mock mockClass: AClass while: [:mock | "testcode here" ] Regards, Steffen _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Hello.
Just a word of warning. The below suggestion modifies the *entire* image, not just the local environment of the test being run. If you augment some commonly used class in this manner in your test(s), it will alter the behavior of other processes running in parallel with the test runner process (e.g. timer triggers). This can lead to occasional crashes of totally unrelated processes in you image. Ladislav Lenart On 4.7.2011 13:32, Boris Popov, DeepCove Labs wrote: > Steffen, > > Here's one way of doing this, > >>> setUp > super setUp. > MyClass become: MyFakeClass. > >>> tearDown > MyClass become: MyFakeClass. > super tearDown. > > Note, #tearDown isn't a typo, you want the exact same statement to flip the references back. > > Or, > > Behaviour>>mock: cls while: block > self become: cls. > ^[block cull: self] ensure: [self become: cls]. > > Set mock: IdentitySet while: [:cls | cls name] "#IdentitySet" > > HTH, > > -Boris > > -----Original Message----- > From: [hidden email] [mailto:[hidden email]] On Behalf Of Steffen Märcker > Sent: Monday, July 04, 2011 5:07 AM > To: vwnc > Subject: [vwnc] Mocking/replacing a Class > > Hi, > > has anybody ever mocked/replaced a class during a test to test code containing something like: > [...] > AClass doSomething. > [...] > Perhaps an approach like > > Mock mockClass: AClass while: [:mock | "testcode here" ] > > Regards, > Steffen > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Indeed, that's the effect, but it's the price you pay for needing this in the first place...
-Boris -----Original Message----- From: Ladislav Lenart [mailto:[hidden email]] Sent: Monday, July 04, 2011 8:39 AM To: Boris Popov, DeepCove Labs Cc: Steffen Märcker; vwnc Subject: Re: [vwnc] Mocking/replacing a Class Hello. Just a word of warning. The below suggestion modifies the *entire* image, not just the local environment of the test being run. If you augment some commonly used class in this manner in your test(s), it will alter the behavior of other processes running in parallel with the test runner process (e.g. timer triggers). This can lead to occasional crashes of totally unrelated processes in you image. Ladislav Lenart On 4.7.2011 13:32, Boris Popov, DeepCove Labs wrote: > Steffen, > > Here's one way of doing this, > >>> setUp > super setUp. > MyClass become: MyFakeClass. > >>> tearDown > MyClass become: MyFakeClass. > super tearDown. > > Note, #tearDown isn't a typo, you want the exact same statement to flip the references back. > > Or, > > Behaviour>>mock: cls while: block > self become: cls. > ^[block cull: self] ensure: [self become: cls]. > > Set mock: IdentitySet while: [:cls | cls name] "#IdentitySet" > > HTH, > > -Boris > > -----Original Message----- > From: [hidden email] [mailto:[hidden email]] On > Behalf Of Steffen Märcker > Sent: Monday, July 04, 2011 5:07 AM > To: vwnc > Subject: [vwnc] Mocking/replacing a Class > > Hi, > > has anybody ever mocked/replaced a class during a test to test code containing something like: > [...] > AClass doSomething. > [...] > Perhaps an approach like > > Mock mockClass: AClass while: [:mock | "testcode here" ] > > Regards, > Steffen > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > _______________________________________________ > vwnc mailing list > [hidden email] > http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
In reply to this post by Steffen Märcker
Dear Steffen,
John Brant's lightweight classes may be relevant: http://www.laputan.org/brant/brant.doc. NB, not the other versions on the web of Wrappers to the Rescue, which are of their ECOOP paper. Anyone using lighweight classes - for mocks? - for other purposes? Yours faithfully Niall Ross >Hi, > >has anybody ever mocked/replaced a class during a test to test code >containing something like: > [...] > AClass doSomething. > [...] >Perhaps an approach like > >Mock mockClass: AClass while: [:mock | "testcode here" ] > >Regards, >Steffen >_______________________________________________ >vwnc mailing list >[hidden email] >http://lists.cs.uiuc.edu/mailman/listinfo/vwnc > > > > _______________________________________________ vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Thanks Vladimir, Boris. Actually I thought of #become: too.
Niall, I'll look into that paper. But which other version are you referring to? Regards, Steffen Am 04.07.2011, 17:01 Uhr, schrieb Niall Ross <[hidden email]>: > Dear Steffen, > John Brant's lightweight classes may be relevant: > http://www.laputan.org/brant/brant.doc. > > NB, not the other versions on the web of Wrappers to the Rescue, which > are of their ECOOP paper. > > Anyone using lighweight classes > > - for mocks? > > - for other purposes? > > Yours faithfully > Niall Ross > >> Hi, >> >> has anybody ever mocked/replaced a class during a test to test code >> containing something like: >> [...] >> AClass doSomething. >> [...] >> Perhaps an approach like >> >> Mock mockClass: AClass while: [:mock | "testcode here" ] >> >> Regards, >> Steffen >> _______________________________________________ >> vwnc mailing list >> [hidden email] >> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc >> >> >> > vwnc mailing list [hidden email] http://lists.cs.uiuc.edu/mailman/listinfo/vwnc |
Free forum by Nabble | Edit this page |