[ANN] DoubleAgents: A Test Double Library for Visualworks

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

[ANN] DoubleAgents: A Test Double Library for Visualworks

Randy Coulman

All,

I have just released DoubleAgents, a library for creating "test doubles" in Visualworks Smalltalk.

DoubleAgents is available in the Cincom Public Store Repository. A snapshot of the current version is also on GitHub. The Readme file on GitHub includes high-level documentation if you'd like more information before diving in.

The full release announcement is on my blog, Courageous Software.

Thanks,
Randy

--
Randy Coulman
Email: [hidden email]
Home: http://randycoulman.com
Twitter: @randycoulman      GitHub: randycoulman

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Steffen Märcker
Hi Randy,

it looks very interesting. Thanks for making this public. Have you had a  
look at the framework sMock, too? Could you please point out the main  
differences?

Regards, Steffen



Am 30.04.2013, 16:16 Uhr, schrieb Randy Coulman <[hidden email]>:

> All,
>
> I have just released
> DoubleAgents<https://github.com/randycoulman/DoubleAgents>,
> a library for creating "test doubles" in Visualworks Smalltalk.
>
> DoubleAgents is available in the Cincom Public Store
> Repository<http://www.cincomsmalltalk.com/CincomSmalltalkWiki/Public+Store+Repository>.
> A
> snapshot of the current version is also on
> GitHub<https://github.com/randycoulman/DoubleAgents>.
> The Readme file on GitHub includes high-level documentation if you'd like
> more information before diving in.
>
> The full release announcement is on my blog, Courageous
> Software<http://randycoulman.com/blog/2013/04/30/double-agents-a-test-double-library-for-visualworks-smalltalk/>
> .
>
> Thanks,
> Randy


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Randy Coulman

Hi, Steffen,

I wasn't aware of sMock before. Thanks for pointing it out. It looks like a pretty good framework. I haven't worked with it, but I think I like the API better than I like SmallMock's API, which is what I was using before I wrote DoubleAgents.

After a brief look, the main differences I see:

  • sMock only supports what I call "standalone doubles". It doesn't support in-place/partial doubles where you can mock or stub individual methods on an existing instance or class. DoubleAgents does support those, but requires some deep Smalltalk magic to make that work.

  • sMock can create test doubles that aren't based on an existing class; DoubleAgents requires an existing class or instance so that it can do API verification. I've considered relaxing this restriction, but haven't found a need to do so yet.

  • sMock uses a "cascading message" style of API to program mocks, whereas DoubleAgents uses a single message approach. sMock's approach results in a thinner, more flexible API. I considered this style of API for DoubleAgents, but felt that the resulting client code became too verbose and dominated the test. That's a personal preference, though. Most mocking frameworks tend to use the cascading message approach because of its flexibility.

  • sMock mocks have a separate Proxy object that has to be accessed. DoubleAgents are their own proxy.

  • Both sMock and DoubleAgents provide a TestCase subclass that registers doubles and automatically verifies them. Because DoubleAgents always registers doubles with the singleton Agency, its test setUp and tearDown are much simpler than in sMock. This makes it much less work to use in a TestCase that can't inherit from the provided base provided TestCase class.

  • sMock provides a TestCase subclass for both SUnit and SUnitToo; DoubleAgents only provides one for SUnitToo at present. Unfortunately, though, sMock's TestCase subclasses are both in the same package, so clients are forced to have both frameworks loaded at the same time. I'd want to separate those out into their own packages.

What are your thoughts?

Randy



On Wed, May 1, 2013 at 2:27 AM, Steffen Märcker <[hidden email]> wrote:
Hi Randy,

it looks very interesting. Thanks for making this public. Have you had a look at the framework sMock, too? Could you please point out the main differences?

Regards, Steffen



Am 30.04.2013, 16:16 Uhr, schrieb Randy Coulman <[hidden email]>:

All,

I have just released
DoubleAgents<https://github.com/randycoulman/DoubleAgents>,

a library for creating "test doubles" in Visualworks Smalltalk.

DoubleAgents is available in the Cincom Public Store
Repository<http://www.cincomsmalltalk.com/CincomSmalltalkWiki/Public+Store+Repository>.

A
snapshot of the current version is also on
GitHub<https://github.com/randycoulman/DoubleAgents>.

The Readme file on GitHub includes high-level documentation if you'd like
more information before diving in.

The full release announcement is on my blog, Courageous
Software<http://randycoulman.com/blog/2013/04/30/double-agents-a-test-double-library-for-visualworks-smalltalk/>
.

Thanks,
Randy


_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



--
Randy Coulman
Email: [hidden email]
Home: http://randycoulman.com
Twitter: @randycoulman      GitHub: randycoulman

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Steffen Märcker
Hi Randy,

thanks for the explanation. DoubleAgents appear really interesting to me.  
I think I'll give it a try soon. Maybe for the reducers stuff or while  
reworking the SimpleXO / SimpleXPath tests. The latter uses sMock up to  
now.

Do DAs support mocking a class, too? How would you do that?

> in-place/partial doubles where you can mock or stub individual methods  
> on an existing instance or class.

Nice.

> Unfortunately, though, sMock's TestCase subclasses are both
> in the same package, so clients are forced to have both
> frameworks loaded at the same time.

Mmh, for me sMock works well with only one testing framework loaded. One  
can safely ignore the error message on load. Though, it would be nice to  
load the proper test class automagically, dependent on the loaded  
framework.

Regards, Steffen
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Randy Coulman
What do you mean by "mocking a class"?  Can you give me an example?

Thanks,
Randy


On Tue, May 14, 2013 at 10:12 AM, Steffen Märcker <[hidden email]> wrote:
Hi Randy,

thanks for the explanation. DoubleAgents appear really interesting to me. I think I'll give it a try soon. Maybe for the reducers stuff or while reworking the SimpleXO / SimpleXPath tests. The latter uses sMock up to now.

Do DAs support mocking a class, too? How would you do that?


in-place/partial doubles where you can mock or stub individual methods on an existing instance or class.

Nice.


Unfortunately, though, sMock's TestCase subclasses are both
in the same package, so clients are forced to have both
frameworks loaded at the same time.

Mmh, for me sMock works well with only one testing framework loaded. One can safely ignore the error message on load. Though, it would be nice to load the proper test class automagically, dependent on the loaded framework.

Regards, Steffen



--
Randy Coulman
Email: [hidden email]
Home: http://randycoulman.com
Twitter: @randycoulman      GitHub: randycoulman

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Steffen Märcker
Say, we have MyClass that defines myMethod on the class side, e.g.

> MyClass class>>myMethod
>    "fancy stuff"

The code to be tested is given that class in some way and uses it, say

> result := suspectObject doStuffWithClass: MyClass.

Can I stub myMethod with DoubleAgents? Maybe similar to

> classDouble := MyClass class doubleAgent.
> classDouble stub: #myMethod return: 42.
> result := suspectObject doStuffWithClass: classDouble.

Regards, Steffen



Am 14.05.2013, 20:11 Uhr, schrieb Randy Coulman <[hidden email]>:

> What do you mean by "mocking a class"?  Can you give me an example?
>
> Thanks,
> Randy
>
>
> On Tue, May 14, 2013 at 10:12 AM, Steffen Märcker <[hidden email]> wrote:
>
>> Hi Randy,
>>
>> thanks for the explanation. DoubleAgents appear really interesting to  
>> me.
>> I think I'll give it a try soon. Maybe for the reducers stuff or while
>> reworking the SimpleXO / SimpleXPath tests. The latter uses sMock up to  
>> now.
>>
>> Do DAs support mocking a class, too? How would you do that?
>>
>>
>>  in-place/partial doubles where you can mock or stub individual methods  
>> on
>>> an existing instance or class.
>>>
>>
>> Nice.
>>
>>
>>  Unfortunately, though, sMock's TestCase subclasses are both
>>> in the same package, so clients are forced to have both
>>> frameworks loaded at the same time.
>>>
>>
>> Mmh, for me sMock works well with only one testing framework loaded. One
>> can safely ignore the error message on load. Though, it would be nice to
>> load the proper test class automagically, dependent on the loaded  
>> framework.
>>
>> Regards, Steffen
>>
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Randy Coulman
OK, I understand what you're looking for.  I could think of a couple of interpretations.

You basically have two options:

1. You can make a complete double of the class like this:

classDouble := DoubleAgent of: MyClass class.
classDouble stub: #myMethod return: 42.
result := suspectObject doStuffWithClass: classDouble.

If this is a common use case, then I should think about adding some kind of convenience protocol to handle it.

2. You can use an in-place double on the original class like this:

classDouble := MyClass classSideDouble.
classDouble stub: #myMethod return: 42.
result := suspectObject doStuffWithClass: classDouble.


I see the tradeoffs between the two as follows:

 * The complete double will not respond to any other messages than those you stub or mock; the in-place double will retain its original behavior for any methods that you don't mention.

* The complete double has to be injected into the object under test; the in-place double does not.

* The complete double will not impact any other objects that use that class; the in-place double will have a global effect.

Randy


On Wed, May 15, 2013 at 2:25 AM, Steffen Märcker <[hidden email]> wrote:
Say, we have MyClass that defines myMethod on the class side, e.g.

MyClass class>>myMethod
   "fancy stuff"

The code to be tested is given that class in some way and uses it, say

result := suspectObject doStuffWithClass: MyClass.

Can I stub myMethod with DoubleAgents? Maybe similar to

classDouble := MyClass class doubleAgent.
classDouble stub: #myMethod return: 42.
result := suspectObject doStuffWithClass: classDouble.

Regards, Steffen



Am 14.05.2013, 20:11 Uhr, schrieb Randy Coulman <[hidden email]>:


What do you mean by "mocking a class"?  Can you give me an example?

Thanks,
Randy


On Tue, May 14, 2013 at 10:12 AM, Steffen Märcker <[hidden email]> wrote:

Hi Randy,

thanks for the explanation. DoubleAgents appear really interesting to me.
I think I'll give it a try soon. Maybe for the reducers stuff or while
reworking the SimpleXO / SimpleXPath tests. The latter uses sMock up to now.

Do DAs support mocking a class, too? How would you do that?


 in-place/partial doubles where you can mock or stub individual methods on
an existing instance or class.


Nice.


 Unfortunately, though, sMock's TestCase subclasses are both
in the same package, so clients are forced to have both
frameworks loaded at the same time.


Mmh, for me sMock works well with only one testing framework loaded. One
can safely ignore the error message on load. Though, it would be nice to
load the proper test class automagically, dependent on the loaded framework.

Regards, Steffen

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



--
Randy Coulman
Email: [hidden email]
Home: http://randycoulman.com
Twitter: @randycoulman      GitHub: randycoulman

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Steffen Märcker
In reply to this post by Randy Coulman
Dear Randy,

is there an easy way to check, that no stubbed/mocked methods are left in  
some MethodDictionary? I somehow managed to have a stubbed method left in  
the class Array. I have no idea how it got there and had to remove it by  
hand. I did not (yet) use any in-place class-side doubles. However, I  
wonder if there are any other classes with zombie methods.

Regards,
Steffen


Am 30.04.2013, 16:16 Uhr, schrieb Randy Coulman <[hidden email]>:

> All,
>
> I have just released
> DoubleAgents<https://github.com/randycoulman/DoubleAgents>,
> a library for creating "test doubles" in Visualworks Smalltalk.
>
> DoubleAgents is available in the Cincom Public Store
> Repository<http://www.cincomsmalltalk.com/CincomSmalltalkWiki/Public+Store+Repository>.
> A
> snapshot of the current version is also on
> GitHub<https://github.com/randycoulman/DoubleAgents>.
> The Readme file on GitHub includes high-level documentation if you'd like
> more information before diving in.
>
> The full release announcement is on my blog, Courageous
> Software<http://randycoulman.com/blog/2013/04/30/double-agents-a-test-double-library-for-visualworks-smalltalk/>
> .
>
> Thanks,
> Randy
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Steffen Märcker
... I mean some automatic way rather than searching manually via  
Object>>allSubclasses or MethodDictionary>>allInstances.

Am 26.05.2013, 18:14 Uhr, schrieb Steffen Märcker <[hidden email]>:

> Dear Randy,
>
> is there an easy way to check, that no stubbed/mocked methods are left  
> in some MethodDictionary? I somehow managed to have a stubbed method  
> left in the class Array. I have no idea how it got there and had to  
> remove it by hand. I did not (yet) use any in-place class-side doubles.  
> However, I wonder if there are any other classes with zombie methods.
>
> Regards,
> Steffen
>
>
> Am 30.04.2013, 16:16 Uhr, schrieb Randy Coulman <[hidden email]>:
>
>> All,
>>
>> I have just released
>> DoubleAgents<https://github.com/randycoulman/DoubleAgents>,
>> a library for creating "test doubles" in Visualworks Smalltalk.
>>
>> DoubleAgents is available in the Cincom Public Store
>> Repository<http://www.cincomsmalltalk.com/CincomSmalltalkWiki/Public+Store+Repository>.
>> A
>> snapshot of the current version is also on
>> GitHub<https://github.com/randycoulman/DoubleAgents>.
>> The Readme file on GitHub includes high-level documentation if you'd  
>> like
>> more information before diving in.
>>
>> The full release announcement is on my blog, Courageous
>> Software<http://randycoulman.com/blog/2013/04/30/double-agents-a-test-double-library-for-visualworks-smalltalk/>
>> .
>>
>> Thanks,
>> Randy
> _______________________________________________
> 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
Reply | Threaded
Open this post in threaded view
|

Re: [ANN] DoubleAgents: A Test Double Library for Visualworks

Randy Coulman
In reply to this post by Steffen Märcker

Hi Steffen,

If you aren't using any in-place doubles, there shouldn't be any stubbed or mocked methods left over. "Normal" doubles don't do anything tricky with method dictionaries.

Typically, if you've got something left laying around, doing an Agency forceReset should clean things up. If that doesn't work, search for DoubleAgent allGeneralInstances and send #_tearDown to them.

If that doesn't work, let me know and I'll see if I can come up with some other ideas for you to try.

Randy


On Sun, May 26, 2013 at 9:14 AM, Steffen Märcker <[hidden email]> wrote:
Dear Randy,

is there an easy way to check, that no stubbed/mocked methods are left in some MethodDictionary? I somehow managed to have a stubbed method left in the class Array. I have no idea how it got there and had to remove it by hand. I did not (yet) use any in-place class-side doubles. However, I wonder if there are any other classes with zombie methods.

Regards,
Steffen


Am 30.04.2013, 16:16 Uhr, schrieb Randy Coulman <[hidden email]>:

All,

I have just released
DoubleAgents<https://github.com/randycoulman/DoubleAgents>,

a library for creating "test doubles" in Visualworks Smalltalk.

DoubleAgents is available in the Cincom Public Store
Repository<http://www.cincomsmalltalk.com/CincomSmalltalkWiki/Public+Store+Repository>.

A
snapshot of the current version is also on
GitHub<https://github.com/randycoulman/DoubleAgents>.

The Readme file on GitHub includes high-level documentation if you'd like
more information before diving in.

The full release announcement is on my blog, Courageous
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc



--
Randy Coulman
Email: [hidden email]
Home: http://randycoulman.com
Twitter: @randycoulman      GitHub: randycoulman

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc