|
From: Thorne N. M. <Nig...@an...> - 2004-07-07 05:19:00
|
Hi=20Owen,=20
=20
I=20was=20in=20a=20similar=20state.=20
=20
I=20was=20writing=20a=20simple=20Wiki.=20
To=20test=20a=20method=20on=20the=20wiki=20object=20I=20needed=20the=20wik=
i=20object=20to=20be=20in=20a
specific=20state=20(ie=20have=20a=20certain=20page=20loaded)
The=20Wiki=20was=20talking=20to=20a=20mock=20PageRepository.=20
To=20initalise=20the=20wiki=20ready=20for=20the=20test=20I=20had=20to=20te=
ll=20the=20wiki=20to=20load
a=20page,=20and=20provide=20the=20mock=20PageRepository=20with=20the=20pag=
e=20to=20pass=20back.
This=20required=20me=20to=20set=20up=20an=20expectation.=20
=20
Notice,=20none=20of=20this=20was=20actually=20the=20focus=20of=20the=20tes=
t.
=20
In=20the=20test=20I=20then=20wanted=20to=20perform=20some=20action=20and=20=
then=20call=20verify=20to
see=20if=20the=20PageRepository=20etc=20was=20used=20correctly.=20
=20
It=20would=20have=20been=20nice,=20once=20I=20had=20the=20Wiki=20in=20the=20=
state=20I=20required,=20to
be=20able=20to=20clear=20all=20expectations=20so=20that=20the=20only=20exp=
ectations=20being
tested=20by=20the=20verify=20method=20were=20the=20ones=20related=20to=20t=
he=20method=20under
test,=20not=20the=20setup=20code.=20
=20
I=20think=20this=20is=20the=20situation=20Paul=20is=20talking=20about=20to=
o.=20
Cheers
Nigel
________________________________
From:=20n...@li...
[mailto:nmo...@li...]=20On=20Behalf=20Of=20Ow=
en
Rogers
Sent:=20Wednesday,=207=20July=202004=201:51=20PM
To:=20P...@vi...
Cc:=20n...@li...
Subject:=20[Nmock-general]=20RE:=20NMock
=20
hi=20paul,=20
i'm=20still=20not=20sure=20i=20understand=20why=20you=20are=20concerned=20=
about=20repeatedly
verifying=20the=20results=20of=20previously=20called=20methods.=20=20if=20=
the=20methods=20were
either=20called=20too=20many=20times=20or=20not=20called=20enough=20or=20w=
ere=20called=20with
the=20wrong=20parameters,=20then=20the=20call=20to=20verify=20would=20have=
=20thrown=20an
exception.=20=20so=20you=20should=20be=20able=20to=20safely=20assume=20tha=
t=20if=20you=20make=20it
past=20the=20verify=20statement,=20then=20everything=20is=20a-ok.=20
but=20anyway,=20rather=20than=20continue=20to=20debate=20this,=20i=20thoug=
ht=20i=20would=20write
some=20code=20to=20see=20if=20that=20helped=20clear=20things=20up.=20=20he=
re's=20what=20i=20came=20up
with:=20
=20=20=20=20=20=20=20=20public=20class=20ResetableDynamicMock=20:=20Dynami=
cMock=20
=20=20=20=20=20=20=20=20{=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20public=20ResetableDynamicM=
ock(Type=20type)=20:=20base(type)=20{}=20
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20public=20ResetableDynamicM=
ock(Type=20type,=20string=20name)=20:
base(type,=20name)=20{}=20
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20public=20ResetableDynamicM=
ock(Type=20type,=20string=20name,=20Type
superclassIfTypeIsInterface)=20:=20base(type,=20name,
superclassIfTypeIsInterface)=20{=20}=20
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20public=20override=20void=20=
Verify()=20
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20{=20
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20ba=
se.Verify();=20
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20me=
thods.Clear();=20
=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20=20}=20
=20=20=20=20=20=20=20=20}=20
NB.=20=20i=20had=20to=20make=20the=20"methods"=20member=20protected=20in=20=
the=20Mock=20base
class.=20=20does=20this=20kind=20of=20do=20what=20you=20are=20looking=20fo=
r?=20=20if=20so,=20could=20you
try=20it=20out=20and=20let=20us=20know=20if=20it=20produces=20the=20result=
s=20that=20you=20expect?
if=20other=20people=20think=20that=20having=20something=20like=20this=20wo=
uld=20be=20a=20useful
addition=20to=20nmock,=20we=20can=20always=20add=20it.=20
cheers,=20
owen.
---
R.=20Owen=20Rogers
ThoughtWorks=20Technologies=20(India)=20Pvt=20Ltd.
ThoughtWorks=20-=20Deliver=20with=20passion!
ThoughtWorks=20is=20always=20looking=20for=20talented=20people=20who=20are=
=20passionate
about=20technology.=20=20To=20find=20out=20more=20about=20a=20career=20at=20=
ThoughtWorks=20go=20to
http://www.thoughtworks.com/career/.=20
=20
"Paul=20Brousseau"=20<Pau...@vi...>=20
06/07/2004=2021:37=20
=20=20=20=20=20=20=20=20
=20=20=20=20=20=20=20=20To:=20=20=20=20=20=20=20=20"Owen=20Rogers"=20<ORog=
er...@th...>=20
=20=20=20=20=20=20=20=20cc:=20=20=20=20=20=20=20=20<nmo...@li...=
urceforge.net>=20
=20=20=20=20=20=20=20=20Subject:=20=20=20=20=20=20=20=20RE:=20NMock
It's=20not=20so=20much=20a=20problem=20as=20a=20possible=20inconvinience=20=
at=20times.=20=20I
think=20my=20sample=20below=20didn't=20properly=20set=20up=20the=20situati=
on.=20=20Let's=20say
that=20I=20have=20method=20X=20that=20I=20want=20to=20test,=20but=20to=20g=
et=20to=20the=20right=20state,
I=20have=20to=20call=20methods=20A,=20B,=20C,=20D,=20and=20E,=20each=20of=20=
which=20result=20in=20calls
to=20the=20Mock=20object.=20=20It=20would=20be=20easier=20for=20me=20to=20=
not=20have=20to=20worry
about=20counting=20the=20various=20method=20calls=20in=20that=20setup=20st=
age.=20=20If=20I=20could
wipe=20out=20my=20expectations,=20then=20I=20would=20only=20have=20to=20ch=
eck=20the=20stuff=20that
goes=20along=20with=20method=20X.=20=20So=20there's=20nothing=20wrong=20wi=
th=20calling=20Verify
multiple=20times,=20but=20I'd=20like=20not=20to=20have=20to=20think=20abou=
t=20verifying=20the
results=20of=20methods=20A-E=20(say,=20because=20I've=20already=20verified=
=20that=20they
work=20elsewhere).=20=20=20
=20=20
It's=20ultimately=20just=20a=20matter=20of=20convinience.=20
=20=20
Thanks!=20
=20=20
=20=20
-----Original=20Message-----
From:=20Owen=20Rogers=20[mailto:OR...@th...]
Sent:=20Saturday,=20July=2003,=202004=203:37=20AM
To:=20Paul=20Brousseau
Cc:=20n...@li...
Subject:=20Re:=20NMock
hi=20paul,=20
what=20sort=20of=20problem=20do=20you=20receive=20from=20nmock=20when=20yo=
u=20try=20to=20do=20this?
AFAIK,=20there=20is=20nothing=20stopping=20you=20from=20calling=20Verify=20=
as=20many=20times
as=20you=20like.=20=20why=20is=20it=20important=20to=20reset=20the=20expec=
tations?=20=20is=20there
any=20problem=20with=20just=20accumulating=20them=20until=20the=20end=20of=
=20the=20test?=20
cheers,=20
owen.=20
---
R.=20Owen=20Rogers
ThoughtWorks=20Technologies=20(India)=20Pvt=20Ltd.
ThoughtWorks=20-=20Deliver=20with=20passion!
ThoughtWorks=20is=20always=20looking=20for=20talented=20people=20who=20are=
=20passionate
about=20technology.=20=20To=20find=20out=20more=20about=20a=20career=20at=20=
ThoughtWorks=20go=20to
http://www.thoughtworks.com/career/.=20
=20
"Paul=20Brousseau"=20<Pau...@vi...>=20
03/07/2004=2000:03=20
=20=20=20=20=20=20=20=20
=20=20=20=20=20=20=20To:=20=20=20=20=20=20=20=20<jo...@th...>,
<cst...@th...>,=20<or...@th...>=20
=20=20=20=20=20=20=20cc:=20=20=20=20=20=20=20=20=20
=20=20=20=20=20=20=20Subject:=20=20=20=20=20=20=20=20NMock
Hello!=20=20I'm=20using=20NMock=20for=20a=20project,=20and=20I=20need=20it=
=20to=20do=20something
that=20it=20doesn't=20appear=20to=20do=20at=20the=20moment.
I=20would=20like=20to=20be=20able=20to=20set=20up=20a=20dynamic=20mock=20a=
nd=20do=20several=20tests
with=20it=20in=20a=20row,=20resetting=20the=20expectactions=20each=20time.=
=20=20A=20stripped
down=20example:
mockPageView.Expect("ZoomToFullPage");
controller.UndoZoom();
//=20Do=20assertions=20of=20zoom=20depth.
mockPageView.Verify();
mockPageView.Expect("ZoomToRectangle");
controller.ZoomToRectangle(new=20RectangleF(0,=200,=205f,=205f));
//=20Do=20assertions=20of=20zoom=20depth.
mockPageView.Verify();
mockPageView.Expect("ZoomToFullPage");
controller.UndoZoom();
//=20Do=20assertions=20of=20zoom=20depth.
mockPageView.Verify();
mockPageView.Expect("ZoomToRectangle");
mockPageView.Expect("ZoomToFullPage");
controller.ZoomToRectangle(new=20RectangleF(0,=200,=205f,=205f));
controller.ZoomToFullPage();
//=20Do=20assertions=20of=20zoom=20depth.
mockPageView.Verify();
This=20would=20all=20be=20in=20one=20logical=20unit=20test,=20as=20I'm=20i=
nterested=20in
verifying=20a=20certain=20sequence=20of=20events=20(and=20related=20proper=
ties),=20but=20I
want=20to=20make=20sure=20everything=20is=20going=20as=20planned=20along=20=
the=20way.=20=20I=20would
like=20Verify=20to=20clear=20the=20expectactions,=20OR=20make=20an=20expli=
cit=20call=20to
clear=20them.
I=20didn't=20see=20anything=20like=20this=20on=20the=20roadmap.=20=20Are=20=
there=20plans?=20=20If
not,=20does=20this=20seem=20like=20the=20kind=20of=20thing=20that=20a=20re=
asonably=20clever
engineer=20(myself)=20could=20hack=20up=20in=20day,=20without=20having=20p=
revious
expirience=20with=20the=20source?=20=20And=20if=20so,=20would=20you=20acce=
pt=20a=20contribution
back?
Thanks!
Scanned=20for=20viruses=20by=20MessageLabs
Scanned=20for=20viruses=20by=20MessageLabs.=20The=20integrity=20and=20secu=
rity=20of=20this=20message=20cannot=20be=20guaranteed.=20This=20email=20is=
=20intended=20for=20the=20named=20recipient=20only,=20and=20may=20contain=20=
confidential=20information=20and=20proprietary=20material.=20Any=20unautho=
rised=20use=20or=20disclosure=20is=20prohibited. |