Re: Statics and caches and mocks oh my!

Adam Sroka <[email protected]>
Newsgroups gmane.comp.programming.test-driven-development
Message-ID <CALaPUVcWSDtkWxfBzUxYAr81brk2_=EsQZ+JnQNk1_xwPX=kow@mail.gmail.com>
On Wed, Jun 26, 2013 at 10:52 AM, David Burstin <[email protected]>wrote:

> **
>
>
> Another is to create an interface and have the production code use a
> concrete implementation that internally calls the static methods.In testing
> I can inject mocks. Again, this seems messy to me.
>
>
Not having seen the code my gut tells me that this is probably what I would
do. Just create a wrapper API that lets you use the cache in a more OO way
and then write a concrete implementation that delegates to the statics. You
can mock that interface in your tests.


> I personally don't like the use of static objects, but I don't know what a
> better alternative is that would provide long-lived caching and easy
> accessibility from anywhere in the code. Everyone else on the team thinks
> that they are a great solution.
>
>
I would consider the statics a smell. Creating the wrapper API gives you a
seam to test from, and then once you have coverage you can think about
refactoring the statics out without changing the API.


[Non-text portions of this message have been removed]



------------------------------------

Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/testdrivendevelopment/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/testdrivendevelopment/join
    (Yahoo! ID required)

<*> To change settings via email:
    [email protected] 
    [email protected]

<*> To unsubscribe from this group, send an email to:
    [email protected]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.