[Israel.pm] Slightly Off Topic: To Mock or not to Mock?

Shlomi Fish shlomif at iglu.org.il
Tue Apr 20 08:41:39 PDT 2004

Hi all!

Let me describe a situation I encountered now and then ask for your 
hypothetical opinion and what does the general theory of testing and mocking 
has to say about it. 

I am now working on Subversion. Subversion has several layers, and the layer 
in question is called the repository access layer. (or RA). The purpose of 
this layer is to provide a common way to access a Subversion repository. It 
has several drivers: one for accessing the repository directly from the disk 
(ra_local); one for communication over HTTP (and more specifically a custom 
Subversion variant of WebDAV/DeltaV) called ra_dav, and one for talking with 
the Subversion proprietary server - svnserve - called ra_svn. They are all 
called with one unified API provided by the RA layer.

I already successfully implemented the appropriate logic in the ra_local 
layer. I also wrote tests to test the RA function, that at the moment only 
work with local repositories since the other type of RA drivers are not 
implemented yet. Right now, I'm working on the ra_dav logic. Now, it is 
pretty complex because it involves transmitting XML across the HTTP protocol, 
receiving XML back and procesing it.

So now I have two choices, after I finish implementing the ra_dav client 

1. I can implement the logic of mod_dav_svn, which is a custom Apache module 
that serves as the service for ra_dav. It accesses the repository on the 
server's local hard-disk, and transmits it to the ra_dav client in a format 
it can understand.

Then I can test the ra_dav/mod_dav_svn combination with the generic tests I 
wrote for the RA layer.

2. I can code some tests with a mock mod_dav_svn service. This will be a HTTP 
server that will just map responses to requests, without actually querying a 
repository. This I can use to test the correctness of the ra_dav layer.

Now, the question is: is coding the tests in option #2 beneficial and does it 
give any advantages for just being content with the tests in option #1? Why 
mock in this case? Or if not - why not?


	Shlomi Fish

Shlomi Fish      shlomif at iglu.org.il
Homepage:        http://shlomif.il.eu.org/

Quidquid latine dictum sit, altum viditur.
        [Whatever is said in Latin sounds profound.]

More information about the Perl mailing list