Fwd: Re: Proposal for Mock Objects at ESUG 2011

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
24 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Fwd: Re: Proposal for Mock Objects at ESUG 2011

Joseph Pelrine
Hi all,

I took the liberty of forwarding this mail to Tim Mackinnon and Steve
Freeman, who invented the original Mock Objects. Here's Steve's answer.
I'll forward further mails to this list.

-------- Original Message --------
Subject: Re: [Esug-list] Proposal for Mock Objects at ESUG 2011
Date: Fri, 27 May 2011 09:25:30 +0100
From: Steve Freeman <[hidden email]>
To: Joseph Pelrine <[hidden email]>

You should talk to Tim, he wrote a mocks library in about 3 classes
(which is what it should take). He also has some interesting experience
from the Kapital project that doesn't have unit tests.

I hadn't realised that the ST world was behind in this respect.

S.

On 27 May 2011, at 05:41, Joseph Pelrine wrote:

> FYI
>
> -------- Original Message --------
> Subject: [Esug-list] Proposal for Mock Objects at ESUG 2011
> Date: Fri, 27 May 2011 08:36:27 +0400
> From: Dennis Schetinin <[hidden email]>
> To: ESUG Mailing list <[hidden email]>
>
>
>
> Hello!
>
> I'd like to explore interest to Mock Object in Smalltalk society. I'm
> currently working on the topic, preparing a paper and presentation
> targeting at ESUG 2011.
>
> I plan to present Mock Objects technique itself and a framework named
> Mocketry as a tool helping to apply it in practice. Of course I'll
> provide a small example to illustrate some of the ideas.
>
> Apparently, Mocks technique is not popular tool among Smalltalkers. It
> even seems (to me), TDD is not as widely used as it could and should be
> (despite the fact it was born in Smalltalk). I have been using TDD and
> Mocks for many years in different projects with Smalltalk and other
> languages. Sometimes it was hard, sometimes I was even giving it up, but
> by now I think I have sufficient experience to state that TDD in general
> and Mock Objects specifically do deserve (at least) more attention by
> smalltalkers. Yes, Smalltalk is great language and it has great tools.
> This damps some aspects of the problems TDD and Mocks address, but for
> sure does not remove them totally. More than that, I can say I was most
> productive in Smalltalk when I used "classic TDD" and mocks in conjunction.
>
>
> So, are other Smalltalkers interested in this topic? Do you think it
> worth to be presented at the conference? What are the problems you'd
> like to discuss there?
>
> TIA
>
> --
> Dennis Schetinin
> <Attached Message Part.txt>

Steve Freeman

Winner of the Agile Alliance Gordon Pask award 2006
Book: http://www.growing-object-oriented-software.com

+44 (0) 797 179 4105
M3P Limited.  http://www.m3p.co.uk
Registered office. 2 Church Street, Burnham, Bucks, SL1 7HZ.
Company registered in England & Wales. Number 03689627






_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

NiallRoss
Dear Dennis,

 > I'd like to explore interest to Mock Object in Smalltalk society. I'm
 > currently working on the topic, preparing a paper and presentation
 > targeting at ESUG 2011.

Sounds interesting.

Steve Freeman (via Joseph Pelrine) wrote:

> You should talk to Tim, he wrote a mocks library in about 3 classes
> (which is what it should take). He also has some interesting
> experience from the Kapital project that doesn't have unit tests.


Tim Mackinnon mentions mock objects in his talk 'Expressive Testing and
Code for Free' at ESUG 2007 (report reachable from
http://www.esug.org/Conferences).

You remark

 > Apparently, Mocks technique is not popular tool among Smalltalkers.

and Steve, noting that, says

>
> I hadn't realised that the ST world was behind in this respect.

I note that one or two who replied to your earlier post said they had
not needed Mocks, or found them brittle, but I don't think the technique
is _unpopular_ in Smalltalk.  My own take is

1) Smalltalk's power means mocks are not needed as often.  Many a time,
you can get at what you need directly, or by use method wrappers to make
the real objects (or the routes to them) act momentarily as mocks.

Here, I may be saying the same as you:

>> Yes, Smalltalk is great language and it has great tools.
>> This damps some aspects of the problems TDD and Mocks address, but for
>> sure does not remove them totally.
>

2) Another dynamic language feature is that you can more easily
structure tests so the same test can be run against both the mock and
the real object when the latter is available.  (The approach is the same
as in my talk "eXtreme UI Testing" at Smalltalk Solutions 2007, also
reachable from the http://www.esug.org/Conferences page.)

These features may sometimes make people less thorough in setting up a
full mocks framework for their application's tests.
 

>> It even seems (to me), TDD is not as widely used as it could and should
>> be (despite the fact it was born in Smalltalk).
>
I don't think TDD is in the least unpopular or unrespected in
Smalltalk.  However I'm sure you are right when you say it "is not as
widely used as it could and should be", though I'd be surprised if that
were more true of Smalltalk than of other languages.

>> I have been using TDD and
>> Mocks for many years in different projects with Smalltalk and other
>> languages. Sometimes it was hard, sometimes I was even giving it up, but
>> by now I think I have sufficient experience to state that TDD in general
>> and Mock Objects specifically do deserve (at least) more attention by
>> Smalltalkers.  ... I was most productive in Smalltalk when I used
>>  "classic TDD" and mocks in conjunction.
>
If your talk uses your experience to illuminate why what we "could and
should be" doing was "sometimes ... hard ... even giving it up", but
"most productive", that might be very useful to others.

             Yours faithfully
                   Niall Ross


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Hernan Wilkinson-3
Hi Dennis,
 I completely agree with Niall... I participated in the development of a systems, in VASmalltalk & GemStone, that has 23.000 tests that run in 7 minutes and we hardly needed to use mocks... we mostly needed to have polymorphic objets with the real ones and sometimes we used the same test to do it and sometimes we just used the real ones that were created using resources... I prefer to use real objects instead of mocks or test doubles because when using test doubles (which includes mocks) you are not testing the real thing, so for example, I do not use test doubles for objects that are part of the system I'm writing but only for objects outside the system.
 My experience of teaching/coaching TDD shows that test doubles are more important due to its difficulty of using, in statically typed languages, which makes sense because the coupling between the "client" object and the "server" object is the variable's type instead of only the messages that are sent. 
 I also believe that TDD is popular in Smalltalk... why do you think it is not?

 Bye!
 Hernan.

On Fri, May 27, 2011 at 10:16 AM, Niall Ross <[hidden email]> wrote:
Dear Dennis,


> I'd like to explore interest to Mock Object in Smalltalk society. I'm
> currently working on the topic, preparing a paper and presentation
> targeting at ESUG 2011.

Sounds interesting.


Steve Freeman (via Joseph Pelrine) wrote:

You should talk to Tim, he wrote a mocks library in about 3 classes (which is what it should take). He also has some interesting experience from the Kapital project that doesn't have unit tests.


Tim Mackinnon mentions mock objects in his talk 'Expressive Testing and Code for Free' at ESUG 2007 (report reachable from http://www.esug.org/Conferences).

You remark


> Apparently, Mocks technique is not popular tool among Smalltalkers.

and Steve, noting that, says



I hadn't realised that the ST world was behind in this respect.

I note that one or two who replied to your earlier post said they had not needed Mocks, or found them brittle, but I don't think the technique is _unpopular_ in Smalltalk.  My own take is

1) Smalltalk's power means mocks are not needed as often.  Many a time, you can get at what you need directly, or by use method wrappers to make the real objects (or the routes to them) act momentarily as mocks.

Here, I may be saying the same as you:


Yes, Smalltalk is great language and it has great tools.
This damps some aspects of the problems TDD and Mocks address, but for
sure does not remove them totally.


2) Another dynamic language feature is that you can more easily structure tests so the same test can be run against both the mock and the real object when the latter is available.  (The approach is the same as in my talk "eXtreme UI Testing" at Smalltalk Solutions 2007, also reachable from the http://www.esug.org/Conferences page.)

These features may sometimes make people less thorough in setting up a full mocks framework for their application's tests.



It even seems (to me), TDD is not as widely used as it could and should
be (despite the fact it was born in Smalltalk).

I don't think TDD is in the least unpopular or unrespected in Smalltalk.  However I'm sure you are right when you say it "is not as widely used as it could and should be", though I'd be surprised if that were more true of Smalltalk than of other languages.

I have been using TDD and
Mocks for many years in different projects with Smalltalk and other
languages. Sometimes it was hard, sometimes I was even giving it up, but
by now I think I have sufficient experience to state that TDD in general
and Mock Objects specifically do deserve (at least) more attention by
Smalltalkers.  ... I was most productive in Smalltalk when I used

 "classic TDD" and mocks in conjunction.

If your talk uses your experience to illuminate why what we "could and should be" doing was "sometimes ... hard ... even giving it up", but "most productive", that might be very useful to others.

           Yours faithfully
                 Niall Ross


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email ______________________________________________________________________


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: +54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Frank Shearar-3
You miss the point of mocks. Mocks are there to allow you to test your
code quickly and cheaply against things that may not work in a quick
manner.

Further, they allow you to isolate yourself from external systems. If
you need a database running for your tests to pass, you are not unit
testing, but integration testing. You do need to do both, but they
serve different purposes.

Lastly, mocks document the protocols your objects use to collaborate
with each other. They are much more than post-fact assertions.
Someone's already mentioned the excellent Growing Object Oriented
Systems Guided by Tests (Tim wrote the afterword for it).

My two cents? We have at least the beginnings of a framework inside
SSpec, a project which dearly needs some love and attention. It's
globally writable so contributing to it is easy.

In particular, when next I get a chance - hopefully this next month -
I'd like to address some of its quirks, split SSpec's DSL from the
mocking library, integrate SSpec into TestRunner (or at least make the
expectations runnable from TestRunner), and make sure the
TextTestRunner still works.

What I don't want to see is everyone publishing their own incompatible
frameworks or, just as bad, noone doing anything because "oh we don't
need mocks". We do need them, and we need a well-implemented
feature-complete cross-dialect framework.

frank

On 27 May 2011 19:41, Hernan Wilkinson <[hidden email]> wrote:

> Hi Dennis,
>  I completely agree with Niall... I participated in the development of a
> systems, in VASmalltalk & GemStone, that has 23.000 tests that run in 7
> minutes and we hardly needed to use mocks... we mostly needed to
> have polymorphic objets with the real ones and sometimes we used the same
> test to do it and sometimes we just used the real ones that were created
> using resources... I prefer to use real objects instead of mocks or test
> doubles because when using test doubles (which includes mocks) you are not
> testing the real thing, so for example, I do not use test doubles for
> objects that are part of the system I'm writing but only for objects outside
> the system.
>  My experience of teaching/coaching TDD shows that test doubles are more
> important due to its difficulty of using, in statically typed languages,
> which makes sense because the coupling between the "client" object and the
> "server" object is the variable's type instead of only the messages that are
> sent.
>  I also believe that TDD is popular in Smalltalk... why do you think it is
> not?
>  Bye!
>  Hernan.
>
> On Fri, May 27, 2011 at 10:16 AM, Niall Ross <[hidden email]> wrote:
>>
>> Dear Dennis,
>>
>> > I'd like to explore interest to Mock Object in Smalltalk society. I'm
>> > currently working on the topic, preparing a paper and presentation
>> > targeting at ESUG 2011.
>>
>> Sounds interesting.
>>
>> Steve Freeman (via Joseph Pelrine) wrote:
>>
>>> You should talk to Tim, he wrote a mocks library in about 3 classes
>>> (which is what it should take). He also has some interesting experience from
>>> the Kapital project that doesn't have unit tests.
>>
>>
>> Tim Mackinnon mentions mock objects in his talk 'Expressive Testing and
>> Code for Free' at ESUG 2007 (report reachable from
>> http://www.esug.org/Conferences).
>>
>> You remark
>>
>> > Apparently, Mocks technique is not popular tool among Smalltalkers.
>>
>> and Steve, noting that, says
>>
>>>
>>> I hadn't realised that the ST world was behind in this respect.
>>
>> I note that one or two who replied to your earlier post said they had not
>> needed Mocks, or found them brittle, but I don't think the technique is
>> _unpopular_ in Smalltalk.  My own take is
>>
>> 1) Smalltalk's power means mocks are not needed as often.  Many a time,
>> you can get at what you need directly, or by use method wrappers to make the
>> real objects (or the routes to them) act momentarily as mocks.
>>
>> Here, I may be saying the same as you:
>>
>>>> Yes, Smalltalk is great language and it has great tools.
>>>> This damps some aspects of the problems TDD and Mocks address, but for
>>>> sure does not remove them totally.
>>>
>>
>> 2) Another dynamic language feature is that you can more easily structure
>> tests so the same test can be run against both the mock and the real object
>> when the latter is available.  (The approach is the same as in my talk
>> "eXtreme UI Testing" at Smalltalk Solutions 2007, also reachable from the
>> http://www.esug.org/Conferences page.)
>>
>> These features may sometimes make people less thorough in setting up a
>> full mocks framework for their application's tests.
>>
>>
>>>> It even seems (to me), TDD is not as widely used as it could and should
>>>> be (despite the fact it was born in Smalltalk).
>>>
>> I don't think TDD is in the least unpopular or unrespected in Smalltalk.
>>  However I'm sure you are right when you say it "is not as widely used as it
>> could and should be", though I'd be surprised if that were more true of
>> Smalltalk than of other languages.
>>
>>>> I have been using TDD and
>>>> Mocks for many years in different projects with Smalltalk and other
>>>> languages. Sometimes it was hard, sometimes I was even giving it up, but
>>>> by now I think I have sufficient experience to state that TDD in general
>>>> and Mock Objects specifically do deserve (at least) more attention by
>>>> Smalltalkers.  ... I was most productive in Smalltalk when I used
>>>>  "classic TDD" and mocks in conjunction.
>>>
>> If your talk uses your experience to illuminate why what we "could and
>> should be" doing was "sometimes ... hard ... even giving it up", but "most
>> productive", that might be very useful to others.
>>
>>            Yours faithfully
>>                  Niall Ross
>>
>>
>> ______________________________________________________________________
>> This email has been scanned by the MessageLabs Email Security System.
>> For more information please visit http://www.messagelabs.com/email
>> ______________________________________________________________________
>>
>> _______________________________________________
>> Esug-list mailing list
>> [hidden email]
>> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>
>
> --
> Hernán Wilkinson
> Agile Software Development, Teaching & Coaching
> Mobile: +54 - 911 - 4470 - 7207
> email: [hidden email]
> site: http://www.10Pines.com
>
> _______________________________________________
> Esug-list mailing list
> [hidden email]
> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Hernan Wilkinson-3
Hi Frank,

On Fri, May 27, 2011 at 4:42 PM, Frank Shearar <[hidden email]> wrote:
You miss the point of mocks. Mocks are there to allow you to test your
code quickly and cheaply against things that may not work in a quick
manner.

well, not really, I mean 23.000 tests in 7 minutes I think is quick enough :-)
I'm not saying mocks are not important, but I think sometimes they are overused, that's all.
 

Further, they allow you to isolate yourself from external systems. If
you need a database running for your tests to pass, you are not unit
testing, but integration testing. You do need to do both, but they
serve different purposes.

I agree, and I think I mentioned that... we use test doubles (not only mocks) for those types of tests.


Lastly, mocks document the protocols your objects use to collaborate
with each other. They are much more than post-fact assertions.

I don't understand this... why would I use mocks to document protocolos if I alredy have the real objects with their protocol and the tests documenting them with concrete examples? 

 
Someone's already mentioned the excellent Growing Object Oriented
Systems Guided by Tests (Tim wrote the afterword for it).

yeah... but I don't like too much what they proposed is that book :-) (I told that to Tim :-)) but that is another story :-)
 

My two cents? We have at least the beginnings of a framework inside
SSpec, a project which dearly needs some love and attention. It's
globally writable so contributing to it is easy.

In particular, when next I get a chance - hopefully this next month -
I'd like to address some of its quirks, split SSpec's DSL from the
mocking library, integrate SSpec into TestRunner (or at least make the
expectations runnable from TestRunner), and make sure the
TextTestRunner still works.

What I don't want to see is everyone publishing their own incompatible
frameworks or, just as bad, noone doing anything because "oh we don't
need mocks". We do need them, and we need a well-implemented
feature-complete cross-dialect framework.

hey, I'm not saying this should not be done, just only I don't see mocks as important as some people see them, that's all.
I'd like to have a "well-implemented feature-complete cross-dialect framework" mock model of course.

Bye!
Hernan.


frank

On 27 May 2011 19:41, Hernan Wilkinson <[hidden email]> wrote:
> Hi Dennis,
>  I completely agree with Niall... I participated in the development of a
> systems, in VASmalltalk & GemStone, that has 23.000 tests that run in 7
> minutes and we hardly needed to use mocks... we mostly needed to
> have polymorphic objets with the real ones and sometimes we used the same
> test to do it and sometimes we just used the real ones that were created
> using resources... I prefer to use real objects instead of mocks or test
> doubles because when using test doubles (which includes mocks) you are not
> testing the real thing, so for example, I do not use test doubles for
> objects that are part of the system I'm writing but only for objects outside
> the system.
>  My experience of teaching/coaching TDD shows that test doubles are more
> important due to its difficulty of using, in statically typed languages,
> which makes sense because the coupling between the "client" object and the
> "server" object is the variable's type instead of only the messages that are
> sent.
>  I also believe that TDD is popular in Smalltalk... why do you think it is
> not?
>  Bye!
>  Hernan.
>
> On Fri, May 27, 2011 at 10:16 AM, Niall Ross <[hidden email]> wrote:
>>
>> Dear Dennis,
>>
>> > I'd like to explore interest to Mock Object in Smalltalk society. I'm
>> > currently working on the topic, preparing a paper and presentation
>> > targeting at ESUG 2011.
>>
>> Sounds interesting.
>>
>> Steve Freeman (via Joseph Pelrine) wrote:
>>
>>> You should talk to Tim, he wrote a mocks library in about 3 classes
>>> (which is what it should take). He also has some interesting experience from
>>> the Kapital project that doesn't have unit tests.
>>
>>
>> Tim Mackinnon mentions mock objects in his talk 'Expressive Testing and
>> Code for Free' at ESUG 2007 (report reachable from
>> http://www.esug.org/Conferences).
>>
>> You remark
>>
>> > Apparently, Mocks technique is not popular tool among Smalltalkers.
>>
>> and Steve, noting that, says
>>
>>>
>>> I hadn't realised that the ST world was behind in this respect.
>>
>> I note that one or two who replied to your earlier post said they had not
>> needed Mocks, or found them brittle, but I don't think the technique is
>> _unpopular_ in Smalltalk.  My own take is
>>
>> 1) Smalltalk's power means mocks are not needed as often.  Many a time,
>> you can get at what you need directly, or by use method wrappers to make the
>> real objects (or the routes to them) act momentarily as mocks.
>>
>> Here, I may be saying the same as you:
>>
>>>> Yes, Smalltalk is great language and it has great tools.
>>>> This damps some aspects of the problems TDD and Mocks address, but for
>>>> sure does not remove them totally.
>>>
>>
>> 2) Another dynamic language feature is that you can more easily structure
>> tests so the same test can be run against both the mock and the real object
>> when the latter is available.  (The approach is the same as in my talk
>> "eXtreme UI Testing" at Smalltalk Solutions 2007, also reachable from the
>> http://www.esug.org/Conferences page.)
>>
>> These features may sometimes make people less thorough in setting up a
>> full mocks framework for their application's tests.
>>
>>
>>>> It even seems (to me), TDD is not as widely used as it could and should
>>>> be (despite the fact it was born in Smalltalk).
>>>
>> I don't think TDD is in the least unpopular or unrespected in Smalltalk.
>>  However I'm sure you are right when you say it "is not as widely used as it
>> could and should be", though I'd be surprised if that were more true of
>> Smalltalk than of other languages.
>>
>>>> I have been using TDD and
>>>> Mocks for many years in different projects with Smalltalk and other
>>>> languages. Sometimes it was hard, sometimes I was even giving it up, but
>>>> by now I think I have sufficient experience to state that TDD in general
>>>> and Mock Objects specifically do deserve (at least) more attention by
>>>> Smalltalkers.  ... I was most productive in Smalltalk when I used
>>>>  "classic TDD" and mocks in conjunction.
>>>
>> If your talk uses your experience to illuminate why what we "could and
>> should be" doing was "sometimes ... hard ... even giving it up", but "most
>> productive", that might be very useful to others.
>>
>>            Yours faithfully
>>                  Niall Ross
>>
>>
>> ______________________________________________________________________
>> This email has been scanned by the MessageLabs Email Security System.
>> For more information please visit http://www.messagelabs.com/email
>> ______________________________________________________________________
>>
>> _______________________________________________
>> Esug-list mailing list
>> [hidden email]
>> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>
>
> --
> Hernán Wilkinson
> Agile Software Development, Teaching & Coaching
> Mobile: +54 - 911 - 4470 - 7207
> email: [hidden email]
> site: http://www.10Pines.com
>
> _______________________________________________
> Esug-list mailing list
> [hidden email]
> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>



--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: +54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Yann Monclair
Lastly, mocks document the protocols your objects use to collaborate
with each other. They are much more than post-fact assertions.

I don't understand this... why would I use mocks to document protocolos if I alredy have the real objects with their protocol and the tests documenting them with concrete examples? 

The tests will document the use of the methods, but mocks allow you to ensure the separation of public and private protocols by only offering the public protocol on your mocks.
If your code breaches this separation, your tests will fail with MNUs. Obviously, it only works if the mock object is implemented respecting that separation ;-)

Cheers,
Yann

On Fri, May 27, 2011 at 10:05 PM, Hernan Wilkinson <[hidden email]> wrote:
Hi Frank,

On Fri, May 27, 2011 at 4:42 PM, Frank Shearar <[hidden email]> wrote:
You miss the point of mocks. Mocks are there to allow you to test your
code quickly and cheaply against things that may not work in a quick
manner.

well, not really, I mean 23.000 tests in 7 minutes I think is quick enough :-)
I'm not saying mocks are not important, but I think sometimes they are overused, that's all.
 

Further, they allow you to isolate yourself from external systems. If
you need a database running for your tests to pass, you are not unit
testing, but integration testing. You do need to do both, but they
serve different purposes.

I agree, and I think I mentioned that... we use test doubles (not only mocks) for those types of tests.


Lastly, mocks document the protocols your objects use to collaborate
with each other. They are much more than post-fact assertions.

I don't understand this... why would I use mocks to document protocolos if I alredy have the real objects with their protocol and the tests documenting them with concrete examples? 

 
Someone's already mentioned the excellent Growing Object Oriented
Systems Guided by Tests (Tim wrote the afterword for it).

yeah... but I don't like too much what they proposed is that book :-) (I told that to Tim :-)) but that is another story :-)
 

My two cents? We have at least the beginnings of a framework inside
SSpec, a project which dearly needs some love and attention. It's
globally writable so contributing to it is easy.

In particular, when next I get a chance - hopefully this next month -
I'd like to address some of its quirks, split SSpec's DSL from the
mocking library, integrate SSpec into TestRunner (or at least make the
expectations runnable from TestRunner), and make sure the
TextTestRunner still works.

What I don't want to see is everyone publishing their own incompatible
frameworks or, just as bad, noone doing anything because "oh we don't
need mocks". We do need them, and we need a well-implemented
feature-complete cross-dialect framework.

hey, I'm not saying this should not be done, just only I don't see mocks as important as some people see them, that's all.
I'd like to have a "well-implemented feature-complete cross-dialect framework" mock model of course.

Bye!
Hernan.


frank

On 27 May 2011 19:41, Hernan Wilkinson <[hidden email]> wrote:
> Hi Dennis,
>  I completely agree with Niall... I participated in the development of a
> systems, in VASmalltalk & GemStone, that has 23.000 tests that run in 7
> minutes and we hardly needed to use mocks... we mostly needed to
> have polymorphic objets with the real ones and sometimes we used the same
> test to do it and sometimes we just used the real ones that were created
> using resources... I prefer to use real objects instead of mocks or test
> doubles because when using test doubles (which includes mocks) you are not
> testing the real thing, so for example, I do not use test doubles for
> objects that are part of the system I'm writing but only for objects outside
> the system.
>  My experience of teaching/coaching TDD shows that test doubles are more
> important due to its difficulty of using, in statically typed languages,
> which makes sense because the coupling between the "client" object and the
> "server" object is the variable's type instead of only the messages that are
> sent.
>  I also believe that TDD is popular in Smalltalk... why do you think it is
> not?
>  Bye!
>  Hernan.
>
> On Fri, May 27, 2011 at 10:16 AM, Niall Ross <[hidden email]> wrote:
>>
>> Dear Dennis,
>>
>> > I'd like to explore interest to Mock Object in Smalltalk society. I'm
>> > currently working on the topic, preparing a paper and presentation
>> > targeting at ESUG 2011.
>>
>> Sounds interesting.
>>
>> Steve Freeman (via Joseph Pelrine) wrote:
>>
>>> You should talk to Tim, he wrote a mocks library in about 3 classes
>>> (which is what it should take). He also has some interesting experience from
>>> the Kapital project that doesn't have unit tests.
>>
>>
>> Tim Mackinnon mentions mock objects in his talk 'Expressive Testing and
>> Code for Free' at ESUG 2007 (report reachable from
>> http://www.esug.org/Conferences).
>>
>> You remark
>>
>> > Apparently, Mocks technique is not popular tool among Smalltalkers.
>>
>> and Steve, noting that, says
>>
>>>
>>> I hadn't realised that the ST world was behind in this respect.
>>
>> I note that one or two who replied to your earlier post said they had not
>> needed Mocks, or found them brittle, but I don't think the technique is
>> _unpopular_ in Smalltalk.  My own take is
>>
>> 1) Smalltalk's power means mocks are not needed as often.  Many a time,
>> you can get at what you need directly, or by use method wrappers to make the
>> real objects (or the routes to them) act momentarily as mocks.
>>
>> Here, I may be saying the same as you:
>>
>>>> Yes, Smalltalk is great language and it has great tools.
>>>> This damps some aspects of the problems TDD and Mocks address, but for
>>>> sure does not remove them totally.
>>>
>>
>> 2) Another dynamic language feature is that you can more easily structure
>> tests so the same test can be run against both the mock and the real object
>> when the latter is available.  (The approach is the same as in my talk
>> "eXtreme UI Testing" at Smalltalk Solutions 2007, also reachable from the
>> http://www.esug.org/Conferences page.)
>>
>> These features may sometimes make people less thorough in setting up a
>> full mocks framework for their application's tests.
>>
>>
>>>> It even seems (to me), TDD is not as widely used as it could and should
>>>> be (despite the fact it was born in Smalltalk).
>>>
>> I don't think TDD is in the least unpopular or unrespected in Smalltalk.
>>  However I'm sure you are right when you say it "is not as widely used as it
>> could and should be", though I'd be surprised if that were more true of
>> Smalltalk than of other languages.
>>
>>>> I have been using TDD and
>>>> Mocks for many years in different projects with Smalltalk and other
>>>> languages. Sometimes it was hard, sometimes I was even giving it up, but
>>>> by now I think I have sufficient experience to state that TDD in general
>>>> and Mock Objects specifically do deserve (at least) more attention by
>>>> Smalltalkers.  ... I was most productive in Smalltalk when I used
>>>>  "classic TDD" and mocks in conjunction.
>>>
>> If your talk uses your experience to illuminate why what we "could and
>> should be" doing was "sometimes ... hard ... even giving it up", but "most
>> productive", that might be very useful to others.
>>
>>            Yours faithfully
>>                  Niall Ross
>>
>>
>> ______________________________________________________________________
>> This email has been scanned by the MessageLabs Email Security System.
>> For more information please visit http://www.messagelabs.com/email
>> ______________________________________________________________________
>>
>> _______________________________________________
>> Esug-list mailing list
>> [hidden email]
>> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>
>
> --
> Hernán Wilkinson
> Agile Software Development, Teaching & Coaching
> Mobile: <a href="tel:%2B54%20-%20911%20-%204470%20-%207207" value="+5491144707207" target="_blank">+54 - 911 - 4470 - 7207
> email: [hidden email]
> site: http://www.10Pines.com
>
> _______________________________________________
> Esug-list mailing list
> [hidden email]
> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>
>



--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: <a href="tel:%2B54%20-%20911%20-%204470%20-%207207" value="+5491144707207" target="_blank">+54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org



_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Frank Shearar-3
On 27 May 2011 21:25, Yann Monclair <[hidden email]> wrote:

>>> Lastly, mocks document the protocols your objects use to collaborate
>>> with each other. They are much more than post-fact assertions.
>>
>> I don't understand this... why would I use mocks to document protocolos if
>> I alredy have the real objects with their protocol and the tests documenting
>> them with concrete examples?
>
> The tests will document the use of the methods, but mocks allow you to
> ensure the separation of public and private protocols by only offering the
> public protocol on your mocks.
> If your code breaches this separation, your tests will fail with MNUs.
> Obviously, it only works if the mock object is implemented respecting that
> separation ;-)

Indeed, I was just saying to someone off-list that I forgot one of the
more important reasons for using mocks. Firstly that separation of
public and private protocols and, secondly, still being able to test
that our object behaves sanely in response to a bad peer. Using mocks
allows the _test_ to control the interaction - the interaction's laid
out in the test, in other words - and also allows the test to inject
errors: "fail when you call this method the _second_ time", for
instance.

frank

> Cheers,
> Yann
> On Fri, May 27, 2011 at 10:05 PM, Hernan Wilkinson
> <[hidden email]> wrote:
>>
>> Hi Frank,
>>
>> On Fri, May 27, 2011 at 4:42 PM, Frank Shearar <[hidden email]>
>> wrote:
>>>
>>> You miss the point of mocks. Mocks are there to allow you to test your
>>> code quickly and cheaply against things that may not work in a quick
>>> manner.
>>
>> well, not really, I mean 23.000 tests in 7 minutes I think is quick enough
>> :-)
>> I'm not saying mocks are not important, but I think sometimes they are
>> overused, that's all.
>>
>>>
>>> Further, they allow you to isolate yourself from external systems. If
>>> you need a database running for your tests to pass, you are not unit
>>> testing, but integration testing. You do need to do both, but they
>>> serve different purposes.
>>
>> I agree, and I think I mentioned that... we use test doubles (not only
>> mocks) for those types of tests.
>>>
>>> Lastly, mocks document the protocols your objects use to collaborate
>>> with each other. They are much more than post-fact assertions.
>>
>> I don't understand this... why would I use mocks to document protocolos if
>> I alredy have the real objects with their protocol and the tests documenting
>> them with concrete examples?
>>
>>>
>>> Someone's already mentioned the excellent Growing Object Oriented
>>> Systems Guided by Tests (Tim wrote the afterword for it).
>>
>> yeah... but I don't like too much what they proposed is that book :-) (I
>> told that to Tim :-)) but that is another story :-)
>>
>>>
>>> My two cents? We have at least the beginnings of a framework inside
>>> SSpec, a project which dearly needs some love and attention. It's
>>> globally writable so contributing to it is easy.
>>>
>>> In particular, when next I get a chance - hopefully this next month -
>>> I'd like to address some of its quirks, split SSpec's DSL from the
>>> mocking library, integrate SSpec into TestRunner (or at least make the
>>> expectations runnable from TestRunner), and make sure the
>>> TextTestRunner still works.
>>>
>>> What I don't want to see is everyone publishing their own incompatible
>>> frameworks or, just as bad, noone doing anything because "oh we don't
>>> need mocks". We do need them, and we need a well-implemented
>>> feature-complete cross-dialect framework.
>>
>> hey, I'm not saying this should not be done, just only I don't see mocks
>> as important as some people see them, that's all.
>> I'd like to have a "well-implemented feature-complete cross-dialect
>> framework" mock model of course.
>> Bye!
>> Hernan.
>>>
>>> frank
>>>
>>> On 27 May 2011 19:41, Hernan Wilkinson <[hidden email]>
>>> wrote:
>>> > Hi Dennis,
>>> >  I completely agree with Niall... I participated in the development of
>>> > a
>>> > systems, in VASmalltalk & GemStone, that has 23.000 tests that run in 7
>>> > minutes and we hardly needed to use mocks... we mostly needed to
>>> > have polymorphic objets with the real ones and sometimes we used the
>>> > same
>>> > test to do it and sometimes we just used the real ones that were
>>> > created
>>> > using resources... I prefer to use real objects instead of mocks or
>>> > test
>>> > doubles because when using test doubles (which includes mocks) you are
>>> > not
>>> > testing the real thing, so for example, I do not use test doubles for
>>> > objects that are part of the system I'm writing but only for objects
>>> > outside
>>> > the system.
>>> >  My experience of teaching/coaching TDD shows that test doubles are
>>> > more
>>> > important due to its difficulty of using, in statically typed
>>> > languages,
>>> > which makes sense because the coupling between the "client" object and
>>> > the
>>> > "server" object is the variable's type instead of only the messages
>>> > that are
>>> > sent.
>>> >  I also believe that TDD is popular in Smalltalk... why do you think it
>>> > is
>>> > not?
>>> >  Bye!
>>> >  Hernan.
>>> >
>>> > On Fri, May 27, 2011 at 10:16 AM, Niall Ross <[hidden email]> wrote:
>>> >>
>>> >> Dear Dennis,
>>> >>
>>> >> > I'd like to explore interest to Mock Object in Smalltalk society.
>>> >> > I'm
>>> >> > currently working on the topic, preparing a paper and presentation
>>> >> > targeting at ESUG 2011.
>>> >>
>>> >> Sounds interesting.
>>> >>
>>> >> Steve Freeman (via Joseph Pelrine) wrote:
>>> >>
>>> >>> You should talk to Tim, he wrote a mocks library in about 3 classes
>>> >>> (which is what it should take). He also has some interesting
>>> >>> experience from
>>> >>> the Kapital project that doesn't have unit tests.
>>> >>
>>> >>
>>> >> Tim Mackinnon mentions mock objects in his talk 'Expressive Testing
>>> >> and
>>> >> Code for Free' at ESUG 2007 (report reachable from
>>> >> http://www.esug.org/Conferences).
>>> >>
>>> >> You remark
>>> >>
>>> >> > Apparently, Mocks technique is not popular tool among Smalltalkers.
>>> >>
>>> >> and Steve, noting that, says
>>> >>
>>> >>>
>>> >>> I hadn't realised that the ST world was behind in this respect.
>>> >>
>>> >> I note that one or two who replied to your earlier post said they had
>>> >> not
>>> >> needed Mocks, or found them brittle, but I don't think the technique
>>> >> is
>>> >> _unpopular_ in Smalltalk.  My own take is
>>> >>
>>> >> 1) Smalltalk's power means mocks are not needed as often.  Many a
>>> >> time,
>>> >> you can get at what you need directly, or by use method wrappers to
>>> >> make the
>>> >> real objects (or the routes to them) act momentarily as mocks.
>>> >>
>>> >> Here, I may be saying the same as you:
>>> >>
>>> >>>> Yes, Smalltalk is great language and it has great tools.
>>> >>>> This damps some aspects of the problems TDD and Mocks address, but
>>> >>>> for
>>> >>>> sure does not remove them totally.
>>> >>>
>>> >>
>>> >> 2) Another dynamic language feature is that you can more easily
>>> >> structure
>>> >> tests so the same test can be run against both the mock and the real
>>> >> object
>>> >> when the latter is available.  (The approach is the same as in my talk
>>> >> "eXtreme UI Testing" at Smalltalk Solutions 2007, also reachable from
>>> >> the
>>> >> http://www.esug.org/Conferences page.)
>>> >>
>>> >> These features may sometimes make people less thorough in setting up a
>>> >> full mocks framework for their application's tests.
>>> >>
>>> >>
>>> >>>> It even seems (to me), TDD is not as widely used as it could and
>>> >>>> should
>>> >>>> be (despite the fact it was born in Smalltalk).
>>> >>>
>>> >> I don't think TDD is in the least unpopular or unrespected in
>>> >> Smalltalk.
>>> >>  However I'm sure you are right when you say it "is not as widely used
>>> >> as it
>>> >> could and should be", though I'd be surprised if that were more true
>>> >> of
>>> >> Smalltalk than of other languages.
>>> >>
>>> >>>> I have been using TDD and
>>> >>>> Mocks for many years in different projects with Smalltalk and other
>>> >>>> languages. Sometimes it was hard, sometimes I was even giving it up,
>>> >>>> but
>>> >>>> by now I think I have sufficient experience to state that TDD in
>>> >>>> general
>>> >>>> and Mock Objects specifically do deserve (at least) more attention
>>> >>>> by
>>> >>>> Smalltalkers.  ... I was most productive in Smalltalk when I used
>>> >>>>  "classic TDD" and mocks in conjunction.
>>> >>>
>>> >> If your talk uses your experience to illuminate why what we "could and
>>> >> should be" doing was "sometimes ... hard ... even giving it up", but
>>> >> "most
>>> >> productive", that might be very useful to others.
>>> >>
>>> >>            Yours faithfully
>>> >>                  Niall Ross
>>> >>
>>> >>
>>> >> ______________________________________________________________________
>>> >> This email has been scanned by the MessageLabs Email Security System.
>>> >> For more information please visit http://www.messagelabs.com/email
>>> >> ______________________________________________________________________
>>> >>
>>> >> _______________________________________________
>>> >> Esug-list mailing list
>>> >> [hidden email]
>>> >> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>>> >
>>> >
>>> >
>>> > --
>>> > Hernán Wilkinson
>>> > Agile Software Development, Teaching & Coaching
>>> > Mobile: +54 - 911 - 4470 - 7207
>>> > email: [hidden email]
>>> > site: http://www.10Pines.com
>>> >
>>> > _______________________________________________
>>> > Esug-list mailing list
>>> > [hidden email]
>>> > http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>>> >
>>> >
>>
>>
>>
>> --
>> Hernán Wilkinson
>> Agile Software Development, Teaching & Coaching
>> Mobile: +54 - 911 - 4470 - 7207
>> email: [hidden email]
>> site: http://www.10Pines.com
>>
>> _______________________________________________
>> Esug-list mailing list
>> [hidden email]
>> http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
>>
>
>

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Mock Objects at ESUG 2011

Colin Putney-3
In reply to this post by Frank Shearar-3
On Fri, May 27, 2011 at 12:42 PM, Frank Shearar <[hidden email]> wrote:
> You miss the point of mocks. Mocks are there to allow you to test your
> code quickly and cheaply against things that may not work in a quick
> manner.

Not likely. Hernán has been around the block and he speaks from long
experience and deep thinking on software design. If you read his post
a little more carefully, you'll see that he distinguishes between test
doubles in general and mocks as a particular form of test double. He
uses test doubles - you don't get 23,000 tests to run in 7 minutes
without them. It's just *mocks* that are mostly unnecessary.

Personally, I find that mocks are *very* useful in a few very specific
situations, but they can cause problems it other situations. They're
like a very specialized tool - invaluable when you need it, but kept
in the bottom of the toolbox and not used very often. Where I find
them useful is in testing communication. For example, I'll use a
MockWritestream to throw an exception if the code under test writes
something unexpected into the stream. It's handy when testing code
that writes out files in a particular format, or communicates with
remote systems over the network. It might also be useful to test
communications across formal module boundaries, where it's
particularly important that a specific protocol be used - eg, for
something like Prevalayer.

My favourite testing pattern is TrivialImplementation. Instead of
using a test double or an expensive "real" object, I often create a
cheap/trivial implementation of the objects that collaborate with the
objects I'm testing. For example, Monticello2 has several repository
classes. There are implementations that store code in a single file,
in a directory of files, on a remote machine via sockets, on a web
server via HTTP etc. There's also a trivial implementation that just
uses an in-memory Dictionary for storage. It's a complete
implementation of the repository protocol, and Monticello can use it
"for real", but it's not as robust as the other kinds of repository.
All the repository implementations, including MemoryRepository, have a
suite of tests that ensure that they work correctly. But when I'm
testing other parts of Monticello that interact with a repository,
those tests use a MemoryRepository.

I know that BDD folks like to talk about testing behaviour rather than
state, but I don't find the distinction useful. Testing state breaks
the encapsulation of the objects under test, and couples the test too
closely to their internal implementation. Testing behaviour using
mocks *does the same thing*; it just restricts the implementation in a
different way. I find it's better to give the implementation a degree
of freedom by testing "results". Figuring out what result you're
looking for can be difficult - it requires thinking about what a
passing test really tells you.

Here's an example - let's say we we're testing an implementation of
Set. Here's the version that tests state:

| set |
set := Set new.
set add: 3.
self assert: (set instVarNamed: 'array') = #(nil nil nil 3 nil)

Here we test behaviour:

| set |
mock := MockArray new: 5
mock expect: (Message selector: #at:put: arguments: #(4 3)).
set := Set withArray: mock.
set add: 3.

I prefer this approach. It gives the implementation a lot of freedom,
while ensuring that it does what we really want:

| set |
set := Set new.
set add: 3.
self assert: (set includes: 3).

In short, I agree with Hernán. Mocks can be useful, but they're often
overused. In most cases, they're unnecessary.

Colin

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Frank Shearar-3
In reply to this post by Frank Shearar-3
On 27 May 2011 21:56, Colin Putney <[hidden email]> wrote:

> On Fri, May 27, 2011 at 12:42 PM, Frank Shearar <[hidden email]> wrote:
>> You miss the point of mocks. Mocks are there to allow you to test your
>> code quickly and cheaply against things that may not work in a quick
>> manner.
>
> Not likely. Hernán has been around the block and he speaks from long
> experience and deep thinking on software design. If you read his post
> a little more carefully, you'll see that he distinguishes between test
> doubles in general and mocks as a particular form of test double. He
> uses test doubles - you don't get 23,000 tests to run in 7 minutes
> without them. It's just *mocks* that are mostly unnecessary.

Hernan, I didn't mean to bite your head off. Next time I'll pause a bit longer.

> Personally, I find that mocks are *very* useful in a few very specific
> situations, but they can cause problems it other situations. They're
> like a very specialized tool - invaluable when you need it, but kept
> in the bottom of the toolbox and not used very often. Where I find
> them useful is in testing communication. For example, I'll use a
> MockWritestream to throw an exception if the code under test writes
> something unexpected into the stream. It's handy when testing code
> that writes out files in a particular format, or communicates with
> remote systems over the network. It might also be useful to test
> communications across formal module boundaries, where it's
> particularly important that a specific protocol be used - eg, for
> something like Prevalayer.

Indeed, and in these cases and the other appropriate use cases I'd
like to see a nicely written, widely used, standardised framework
precisely so we (I) don't have to write our (my) own.

Anyhow, talk's cheap, and once I've finished my current chunk of work
I'll try beat SSpec into shape.

frank

> My favourite testing pattern is TrivialImplementation. Instead of
> using a test double or an expensive "real" object, I often create a
> cheap/trivial implementation of the objects that collaborate with the
> objects I'm testing. For example, Monticello2 has several repository
> classes. There are implementations that store code in a single file,
> in a directory of files, on a remote machine via sockets, on a web
> server via HTTP etc. There's also a trivial implementation that just
> uses an in-memory Dictionary for storage. It's a complete
> implementation of the repository protocol, and Monticello can use it
> "for real", but it's not as robust as the other kinds of repository.
> All the repository implementations, including MemoryRepository, have a
> suite of tests that ensure that they work correctly. But when I'm
> testing other parts of Monticello that interact with a repository,
> those tests use a MemoryRepository.
>
> I know that BDD folks like to talk about testing behaviour rather than
> state, but I don't find the distinction useful. Testing state breaks
> the encapsulation of the objects under test, and couples the test too
> closely to their internal implementation. Testing behaviour using
> mocks *does the same thing*; it just restricts the implementation in a
> different way. I find it's better to give the implementation a degree
> of freedom by testing "results". Figuring out what result you're
> looking for can be difficult - it requires thinking about what a
> passing test really tells you.
>
> Here's an example - let's say we we're testing an implementation of
> Set. Here's the version that tests state:
>
> | set |
> set := Set new.
> set add: 3.
> self assert: (set instVarNamed: 'array') = #(nil nil nil 3 nil)
>
> Here we test behaviour:
>
> | set |
> mock := MockArray new: 5
> mock expect: (Message selector: #at:put: arguments: #(4 3)).
> set := Set withArray: mock.
> set add: 3.
>
> I prefer this approach. It gives the implementation a lot of freedom,
> while ensuring that it does what we really want:
>
> | set |
> set := Set new.
> set add: 3.
> self assert: (set includes: 3).
>
> In short, I agree with Hernán. Mocks can be useful, but they're often
> overused. In most cases, they're unnecessary.
>
> Colin
>

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Colin Putney-3
On Fri, May 27, 2011 at 2:34 PM, Frank Shearar <[hidden email]> wrote:

> Indeed, and in these cases and the other appropriate use cases I'd
> like to see a nicely written, widely used, standardised framework
> precisely so we (I) don't have to write our (my) own.

FWIW, here's the mock library I use - I think a framework is overkill:

http://source.wiresong.ca/mc/MockLibrary-cwp.7.mcz

Colin

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Frank Shearar-3
On 27 May 2011 22:44, Colin Putney <[hidden email]> wrote:
> On Fri, May 27, 2011 at 2:34 PM, Frank Shearar <[hidden email]> wrote:
>
>> Indeed, and in these cases and the other appropriate use cases I'd
>> like to see a nicely written, widely used, standardised framework
>> precisely so we (I) don't have to write our (my) own.
>
> FWIW, here's the mock library I use - I think a framework is overkill:
>
> http://source.wiresong.ca/mc/MockLibrary-cwp.7.mcz

Cool, I'll take a look. I suppose I could say "library" or "package"
or whatever instead of "framework". It could be as simple as one or
two classes.

frank

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Hernan Wilkinson-3
In reply to this post by Frank Shearar-3

Hernan, I didn't mean to bite your head off. Next time I'll pause a bit longer.

don't worry! It is very common to get passionated about these things and I like that :-), it means we care about them.
I'd like to see the talk at Esug.

Bye,
Hernan.
 

> Personally, I find that mocks are *very* useful in a few very specific
> situations, but they can cause problems it other situations. They're
> like a very specialized tool - invaluable when you need it, but kept
> in the bottom of the toolbox and not used very often. Where I find
> them useful is in testing communication. For example, I'll use a
> MockWritestream to throw an exception if the code under test writes
> something unexpected into the stream. It's handy when testing code
> that writes out files in a particular format, or communicates with
> remote systems over the network. It might also be useful to test
> communications across formal module boundaries, where it's
> particularly important that a specific protocol be used - eg, for
> something like Prevalayer.

Indeed, and in these cases and the other appropriate use cases I'd
like to see a nicely written, widely used, standardised framework
precisely so we (I) don't have to write our (my) own.

Anyhow, talk's cheap, and once I've finished my current chunk of work
I'll try beat SSpec into shape.

frank

> My favourite testing pattern is TrivialImplementation. Instead of
> using a test double or an expensive "real" object, I often create a
> cheap/trivial implementation of the objects that collaborate with the
> objects I'm testing. For example, Monticello2 has several repository
> classes. There are implementations that store code in a single file,
> in a directory of files, on a remote machine via sockets, on a web
> server via HTTP etc. There's also a trivial implementation that just
> uses an in-memory Dictionary for storage. It's a complete
> implementation of the repository protocol, and Monticello can use it
> "for real", but it's not as robust as the other kinds of repository.
> All the repository implementations, including MemoryRepository, have a
> suite of tests that ensure that they work correctly. But when I'm
> testing other parts of Monticello that interact with a repository,
> those tests use a MemoryRepository.
>
> I know that BDD folks like to talk about testing behaviour rather than
> state, but I don't find the distinction useful. Testing state breaks
> the encapsulation of the objects under test, and couples the test too
> closely to their internal implementation. Testing behaviour using
> mocks *does the same thing*; it just restricts the implementation in a
> different way. I find it's better to give the implementation a degree
> of freedom by testing "results". Figuring out what result you're
> looking for can be difficult - it requires thinking about what a
> passing test really tells you.
>
> Here's an example - let's say we we're testing an implementation of
> Set. Here's the version that tests state:
>
> | set |
> set := Set new.
> set add: 3.
> self assert: (set instVarNamed: 'array') = #(nil nil nil 3 nil)
>
> Here we test behaviour:
>
> | set |
> mock := MockArray new: 5
> mock expect: (Message selector: #at:put: arguments: #(4 3)).
> set := Set withArray: mock.
> set add: 3.
>
> I prefer this approach. It gives the implementation a lot of freedom,
> while ensuring that it does what we really want:
>
> | set |
> set := Set new.
> set add: 3.
> self assert: (set includes: 3).
>
> In short, I agree with Hernán. Mocks can be useful, but they're often
> overused. In most cases, they're unnecessary.
>
> Colin
>



--
Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: +54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Dennis Schetinin
Thank you very much for all the replies, comments, criticism, ideas, references… inspiration! I really didn't expect such an interesting discussion to go. And now I clearly see the topic is questionable and worth discussion. I'll for sure explain my point further here and hopefully at conference, just have to think and structure my thoughts before a bit. Once again, thank you! :)

--
Dennis Schetinin

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

stephane ducasse-2
In reply to this post by Hernan Wilkinson-3
what are test doubles?

OK guys we will have a really cool discussion at ESUG :)

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Mock Objects at ESUG 2011

Hernan Wilkinson-3
Test doubles are objects that simulate being other objects... The name
comes from the movies were the double replaces the real actor...
I really dont like the name, i found it confusing, that is why i
prefer to use simulation objects...
Anyway, they include fake pbjects, mock objects, dummy objects and bla
and bla and bla :-) in the end the only impotant thing is for them to
be polimorphic with the object they are replacing implementing a
specific behavior for the test they are being used

On Saturday, May 28, 2011, stephane ducasse <[hidden email]> wrote:
> what are test doubles?
>
> OK guys we will have a really cool discussion at ESUG :)
>

--
*Hernán Wilkinson
Agile Software Development, Teaching & Coaching
Mobile: +54 - 911 - 4470 - 7207
email: [hidden email]
site: http://www.10Pines.com <http://www.10pines.com/>*

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Fwd: Re: Proposal for Mock Objects at ESUG 2011

Tim Mackinnon-2
In reply to this post by Frank Shearar-3
This has been an interesting thread - and it definitely seems that there is enough interested to warrant a further talk on the subject. I encourage Frank to pursue his idea to submit a talk (sadly I can't attend ESUG this year - which I am disappointed about. However maybe Frank and I can confer offline, and I can share some ideas)

As Neil pointed out  (and more for background info) - I did present the ideas behind Mocks (and the library SMock, that was written for Dolphin) - back in 2007. I also did an update at Smalltalks 2009 and used the following screencast - http://www.planningcards.com/Thoughts/SMock%20and%20TDD%20in%20action.htm.

I have to confess that I keep promising to fully port SMock to Pharo/Squeak - and have done most of the work but I got a bit stuck with Monticello and how to properly do extension methods as well as getting diverted onto other things. It also felt that people weren't very interested in the technique so I was writing something more for myself and for researching how it would impact my Smalltalk coding experience. (By the way there is now much more documentation on how to use Monticello, and Pharo is so much better, and with our renewed energy in the UKSmalltalk meetings I'm more inspired to seek some help to get something checked in). It sounds like Frank also has another interesting library that we should compare (and since then I have augmented another internal Mock library on a JPMorgan project which approaches things in a slightly different manner). While SteveF mentioned that we can implement testing strategies in quite a small amount of Smalltalk code - the bulk of code actually comes in making test failures communicate clearly and explicitly as well as giving you a nice level of expression that keeps tests readable (I think these latter points are very important for long lasting, useful tests).

Having said all of this - many of these conversations do indicated a slight misunderstanding of Mocks and where they came from. To fill in a bit of background:

When I helped invent the approach it was very much driven from wanting to do TDD - and although it was originally written in Java it was inspired from my experience in Smalltalk.  I am particularly fond of CRC cards - and the approach of "role-playing" objects and interactions (yet another Smalltalk invention). In our experiments with TDD in 1999, I found that our Java testing seemed "dumbed down - and we were often tempted to add "getter" methods to just test something. It seemed a far cry from Smalltalk and CRC - until we focused back on how to express that role play in our test code by not adding getter methods. Thus if you did take the time to CRC - and looked at who you collaborated with - then expressing that in a test became more interesting. "I am supposed to collaborate with the PayrollCalculator - and if its the end of the month then I should ask it to #calculatePensionFor: employee on: date  for every employee in my dataset. If I get the wrong date, or don't ask about every employee then I should fail the test." We found that if you could focus on encoding the CRC session in your tests, that you got better tests and better code, as well as better test failures. In Java it felt like you got code that was more Smalltalk like.

So I guess I would comment that for us, Mocks were different because we wanted to focus testing on asserting relationships and interactions and less on data values. I read all the literature at the time (there is a massive book on Testing on my bookshelf from that time) - and nothing else seemed to have this same focus (stubs felt more data related). As we played with this more and more, we refactored out useful techniques to ease the assertion of relationships, and someone coined the term "Needs driven development". That is, the act of thinking in this way made you want to have relationships that you could assert against. For me - these were the "interesting tests" that we had been writing back in Connextra that felt better than the others.

I think this also came out of our experiences of using TDD - and the observation that when you write tests for objects that you consider low hanging fruit (because you know you need them, and they seem easy to test) - invariably you make the wrong decision and test that something threw an exception instead of returning a boolean (or better still in Smalltalk, has an ifAbsent: style construct). Of course you only find out about this when you go to plug your well tested object into the place where you need it and discover that if you had just returned true/false then it would be much easier to use. So you go back, rejig the tests and you get a bit further until you discover another slightly wonky decision. After doing this a few times I made a point of saying to my team mates, lets always start with the top most object and write tests that help us learn what these smaller pieces (which we know we need) should actually do. This resonated well with CRC and really brought everything together for us. This is how MockObjects were born (and I asked Steve and Nat if they would like a chapter in their GOOS book about this history - and they happily included it as an afterward at the back).

So coming back to Smalltalk - I still would argue that this CRC technique is very much alive, and I personally still find that "Needs Driven Development" is a useful technique. However it does mean that you get into a chicken and egg situation. If you start testing with a high level object - how do you test or get something working when you are referring to things that don't yet exist? For me, thats where Mocks step in - they are intended to be light weight proxies for things that don't yet exist. You do a CRC session, pick out the highest level object you can - code it (with tests) and mock out the relationships that you recorded on your CRC cards. As you are coding it, you will probably change your mind (writing real code has a way of doing that) - and you modify your lightweight relationship assertions (mocks). This also works best and is easier if you delegate responsibility and avoid returning complicated things (its easier to Mock and happily conforms to the law of Demeter).

When you are happy enough with your top level object - you can then pick on one of those other relationships, and your tests should now show you the "Protocol" that this new object should have. So you create it - and repeat the process. The interesting twist that the screencast I linked to demonstrates - is that in Smalltalk (and indeed in Ruby or Python) we can create MockObjects that don't have any code, however you can use all those assertions to actually generate an object ready for you to test it. I think this is an interesting idea that needs more research (I feel that the right assertions could generate interesting code).

As a final observation - when people talk about TestDoubles and MethodWrappers, I think they are missing the point of mocks as I intended them - as you can't double or wrap something that isn't yet written? So I would say that these techniques are perhaps better suited to code that is already in existence. Of course once you have done TDD with Mocks, and written your code you are then in a place where you can decide what to do? For me - I have kept the mocks in place - however I think in Smalltalk there is possibly a useful "Lint" check that makes sure your mock stays in sync with the underlying code (I haven't written any Slime style rules - but I think it would be interesting). There is also a useful hybrid functionality where you only mock certain methods and pass control to a real object underneath - or "method wrap" and decorate assertions you want on existing methods and pass down to the functionality underneath. I would argue that these are possibly more "maintenance" or "integration" style endeavours - and it would be a shame to not use the purer "Needs driven development" style when you can.

Anyway - I hope this is a useful background and might inspire more work in the area.

Tim


_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Mock Objects at ESUG 2011

Göran Krampe
In reply to this post by Colin Putney-3
Hey!

Stumbled into this thread but just HAVE to respond... Snipping heavily here:

On 05/27/2011 11:11 PM, Colin Putney wrote:
> without them. It's just *mocks* that are mostly unnecessary.

Amen! I have been thinking the rest of the world had gone mad...

> Personally, I find that mocks are *very* useful in a few very specific
> situations, but they can cause problems it other situations. They're
> like a very specialized tool - invaluable when you need it, but kept
> in the bottom of the toolbox and not used very often.

Right.

[SNIP of good stuff]
> I know that BDD folks like to talk about testing behaviour rather than
> state, but I don't find the distinction useful. Testing state breaks
> the encapsulation of the objects under test, and couples the test too
> closely to their internal implementation. Testing behaviour using
> mocks *does the same thing*; it just restricts the implementation in a
> different way.

So refreshingly to see someone that *also* notes that testing using
mocks actually break encapsulation. Thank you, thank you...

regards, Göran

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Mock Objects at ESUG 2011

Frank Shearar-3
2011/5/31 Göran Krampe <[hidden email]>:

> Hey!
>
> Stumbled into this thread but just HAVE to respond... Snipping heavily here:
>
> On 05/27/2011 11:11 PM, Colin Putney wrote:
>>
>> without them. It's just *mocks* that are mostly unnecessary.
>
> Amen! I have been thinking the rest of the world had gone mad...
>
>> Personally, I find that mocks are *very* useful in a few very specific
>> situations, but they can cause problems it other situations. They're
>> like a very specialized tool - invaluable when you need it, but kept
>> in the bottom of the toolbox and not used very often.
>
> Right.
>
> [SNIP of good stuff]
>>
>> I know that BDD folks like to talk about testing behaviour rather than
>> state, but I don't find the distinction useful. Testing state breaks
>> the encapsulation of the objects under test, and couples the test too
>> closely to their internal implementation. Testing behaviour using
>> mocks *does the same thing*; it just restricts the implementation in a
>> different way.
>
> So refreshingly to see someone that *also* notes that testing using mocks
> actually break encapsulation. Thank you, thank you...

Or to rephrase, "documenting the precise nature of the colloboration
between an object and its context documents that precise nature."

In Colin's example, Set's collaboration with Array is purely an
implementation detail and, as he notes, testing the implementation -
whether checking that Set stores the value in the array, or what
messages Set might send to Array - hurts you.

I fail to see how that makes mocks bad. Unless you're railing against
hype? In which case, I agree: there ain't no such thing as a free
lunch, there is no silver bullet, etc etc.

frank

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Mock Objects at ESUG 2011

Dennis Schetinin
In reply to this post by Göran Krampe
First of all, I'm sorry for my English. (And I'll appreciate it very much if someone will point to mistakes of any kind in the following text.)

I attempted to analyze and structure comments, questions and ideas presented in the thread and I think I found one thing that can be a starting point for the discussion (despite the fact the discussion already started… away back).

I've got a strong feeling (I've got it several years ago and had a number of evidences, including several in this thread) that there are (at least) two very different (if not opposite) points of view on mock objects… and it seems to me, the root of this divergence is even deeper and more general — understanding of TDD. So, I think I have to explain my point of view. (Telling "my" here I claim to be an author of all errors, misinterpretations and nonsenses I'll present. But all the good, reasonable and interesting things were invented by other (clever) people.)

So, why and how did I dare to claim TDD is not really popular among Smalltalkers? Because I still believe tests can drive (nearly) all stages of development: not just coding, but also design and even analysis (at least to clarify and formalize results of analysis). But I rarely (if ever) see any artifacts (tests of the kind). Perhaps I'm wrong, but most of the tests I saw were more "acceptance" tests, perhaps even written afterwards. Once again: very likely I'm wrong (and I'll be glad to be, actually).

Why is it important for me to use TDD? Because, as a bad programmer, I need a help. I have a lot of things I must think about during development (won't enumerate, we all know them), so I want a tool that helps me not to think too much — at least, at the points where it is possible at all. (If I misinterpret the word "driving" here, please let me know.) 

Thus, if I write a line of code that is not directly(!) driven by a test, I don't TDD. If I make some up-front design I'm not actually test-driven. Even, if I simply go few steps designing top-down without tests at a very small single stage of development, TDD is broken. If you think it is too extreme and strict — ok, let's talk about "seamless TDD" vs., say, "partial TDD". (Yes, I know about steps of variable size during TDD etc. But I still think it's a bit another thing. Let's judge a bit later…)

So, considering an example by Colin Putney:

| set |
set := Set new.
set add: 3.
self assert: (set includes: 3).

vs

| set |
mock := MockArray new: 5
mock expect: (Message selector: #at:put: arguments: #(4 3)).
set := Set withArray: mock.
set add: 3.

Isn't it obvious mocking array here is an overkill and the first test is better? For sure it is. 

But why? Because there's actually no development in the 1st test. Otherwise, what is it for: #add: or #includes:? Which feature this test makes me to add to the system-under-test (the Set)? I must select, I must think, thus I'm not driven by the test.

Consider also (slightly) another issue: here we have a ready-to-use inner collection for the Set. But if I have no yet? Isn't it a common and very frequent situation during development: I have to implement a (sub)system that comprises several objects working together? (I think I don't have to provide examples here to prove.) Which one should I implement first? I don't know, I have to explore. I must analyze the system, i.e. divide it into subcomponents, find the ones independent and start by implementing them first. 

But what is this process, I've just described? It's a top-down up-front design. Is it test-driven? Obviously, no. Do I have an alternative? Yes, I can use mocks. With Mocketry I could write:

SetTests >> testStoresElementsInInnerCollection
[:collection |
  set := Set withArray: collection.
  [set add: #element] should strictly satisfy: [collection add: #element]] runScenario

Of course, this is a very early step of development, as I'll have to implement an efficient algorithm to check, if element exists in the set before adding it… And with mocks it is very likely I'll be driven to implement it as a pluggable object. Probably, this can make Set a bit more flexible, doesn't it? On the other hand, it can introduce unnecessary complexity. Apparently, this is a good example to explore it further… While I must admit technique of mock object is not a silver bullet, and must be used carefully… just as any other tool.

So…

Conclusion 1: 
Yes, mock objects is a specific tool for specific situations. But as for me, I meet these specific situation almost as frequently, as other, non-specific(?) circumstances. 

Conclusion 2:
I think mocks should be used, first of all, to discover different aspects of functionality and distribute it among various objects. (Documentation, optimization, etc. goes later… if goes at all…)

When I start to work on a new feature, I first try to write an acceptance test. But I never can implement it 'as is'. And I hate to leave it red or mark it as ignored (in any way). So I try to transform it into something I can implement easily and fast. And often this leads me to a test with mocks. This make me to divide complex functionality into smaller blocks and factor them out to collaborators. The trick is to make those objects to behave (one-by-one and altogether)… But that's another (and big) topic.


--
Dennis Schetinin

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
Reply | Threaded
Open this post in threaded view
|

Re: Proposal for Mock Objects at ESUG 2011

Göran Krampe
In reply to this post by Frank Shearar-3
On 05/31/2011 04:59 PM, Frank Shearar wrote:

> 2011/5/31 Göran Krampe<[hidden email]>:
>> So refreshingly to see someone that *also* notes that testing using mocks
>> actually break encapsulation. Thank you, thank you...
>
> Or to rephrase, "documenting the precise nature of the colloboration
> between an object and its context documents that precise nature."
>
> In Colin's example, Set's collaboration with Array is purely an
> implementation detail and, as he notes, testing the implementation -
> whether checking that Set stores the value in the array, or what
> messages Set might send to Array - hurts you.
>
> I fail to see how that makes mocks bad. Unless you're railing against
> hype? In which case, I agree: there ain't no such thing as a free
> lunch, there is no silver bullet, etc etc.

Well, yes, railing against hype. But also railing against writing tests
that work from "the inside" by using mocks. It is of course a matter of
taste, style and in the end weighing pros and cons. But I have seen too
much use of mocks that end up making the tests purely mirror the
implementation - so even the slightest internal modification would break
the test.

regards, Göran

_______________________________________________
Esug-list mailing list
[hidden email]
http://lists.esug.org/mailman/listinfo/esug-list_lists.esug.org
12