[socal-piggies] Mocking sockets

Steve Wedig stevewedig at gmail.com
Mon Jul 30 18:15:53 PDT 2012


Hi Jathan,

We generally wrap third party and IO libraries with our own interface. That
way our unit tests can either mock or
fake<http://martinfowler.com/articles/mocksArentStubs.html>that
interface, and in production we provide the real interface. This
requires dependency
inversion<http://en.wikipedia.org/wiki/Dependency_inversion_principle>,
so none of your code statically imports the IO library (sockets in this
case).

As for Mox, we've only used MockAnything(), which doesn't require passing
in any interface. That sounds like it may solve your immediate challenge.

Best,
Steve

On Mon, Jul 30, 2012 at 4:38 PM, Jathan McCollum <jathan at gmail.com> wrote:

> I have a need to mock the socket module, but without actually importing it
> first. I know some pretty sophisticated mocking can be done with Mox, but
> it requires that you import the real module into the namespace first.
>
> I am doing some work on an embedded system that doesn't have _socket.so,
> which means I can't actually import the socket module, but I need to do
> some mocking of connections.
>
> Anyone have any pointers? Thanks in advance!
>
> --
> Jathan.
> --
>
> _______________________________________________
> socal-piggies mailing list
> socal-piggies at lists.idyll.org
> http://lists.idyll.org/listinfo/socal-piggies
>
>


-- 
Steve Wedig
http://www.linkedin.com/in/wedig
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.idyll.org/pipermail/socal-piggies/attachments/20120730/f5481719/attachment.htm>


More information about the socal-piggies mailing list