[mocha-developer] how does Mocha compare in terms of classical vs mock-based testing, and stubbing???

Greg Hauptmann greg.hauptmann.ruby at gmail.com
Thu Feb 8 05:54:35 EST 2007


Hi David, (all)

I did read this, but re-read briefly again.....arrr....by interface
discovery you were talking about the development concept behind the mock
object TDD concept.   I was on the lookout for some aspect of Mocha that was
going to do a "reflection" style dynamic interface discovery and then build
the mock object from this.  Got it now, so with the Mock object approach the
concept is that you haven't written the code for the collaborators yet.
Let me know if I'm wrong  :)

The only negative I see re potential use of Mocha to solve my "need to stub
out paypal for local testing" is that Mocha seems to extend test cases no?
i.e. this would allow me to unit test my components with paypal stubbed out
in the form of mock object, HOWEVER if I just wanted to do ad hoc
testing/use of my web application (i.e. not driven by a test case) then I'll
still need a separate "test paypal layer" (or stub out paypal in other
words).   If I've still missed something I'd be keen to know.


Tks
Greg



On 2/8/07, David Chelimsky <dchelimsky at gmail.com> wrote:
>
> On 2/7/07, Greg Hauptmann <greg.hauptmann.ruby at gmail.com> wrote:
> > Hi David - I've checked at the Mocha source code and starting having a
> > look.  I'm interested in understanding your comment on interface
> > discovery.   If you (or someone else) is across the Mocha codebase you
> could
> > provide a pointer to where this interface discovery takes please?
>
> Hi Greg - did you read http://jmock.org/oopsla2004.pdf? It explains it
> better than I could.
>
> Read that first and if you have any questions about it feel free to ask.
>
> Cheers,
> David
>
> >
> > Tks
> > greg
> >
> > On 2/5/07, David Chelimsky <dchelimsky at gmail.com> wrote:
> > >
> > > On 2/4/07, Greg Hauptmann <greg.hauptmann.ruby at gmail.com> wrote:
> > > > Hi guys,
> > > >
> > > > I've just been reading Martin Fowler's article re mock versus
> > > > stubbing<http://martinfowler.com/articles/mocksArentStubs.html>where
> > > > he compares traditional TDD testing techniques with mock based
> > > > testing. I'd be interested in comments from a ruby on rails
> perspective
> > > in
> > > > terms of this and Mocha?  For example:
> > > >
> > > > a) Do you see Mocha as a robust way to test Ruby on Rails based
> apps?
> > >
> > > Yes - though I think of mocking as one tool among many in a robust
> > > testing-toolkit.
> > >
> > > >
> > > > b) Why would one use Mocha over traditional non-mock object based
> > > testing
> > > > for Ruby on Rails?
> > >
> > > Interface Discovery!!!!!! Read http://jmock.org/oopsla2004.pdf for
> > > more info on that.
> > >
> > > >
> > > > c) Is Mocha a good choice for stubbing out other components that the
> > > rails
> > > > app may interact with, for the purpose of testing?
> > >
> > > Short version: Yes.
> > >
> > > Longer version: A guideline that I like to follow is to wrap 3rd party
> > > APIs with thin adapters that provide context-appropriate method names
> > > and only those that your app needs. Then you mock your own API, not
> > > the 3rd party API. You still need to test your adapter, but that test
> > > is isolated from the tests that are about your application and what it
> > > does.
> > >
> > > Cheers,
> > > David
> > >
> > > >
> > > > Tks
> > > > Greg
> > > > _______________________________________________
> > > > mocha-developer mailing list
> > > > mocha-developer at rubyforge.org
> > > > http://rubyforge.org/mailman/listinfo/mocha-developer
> > > >
> > > _______________________________________________
> > > mocha-developer mailing list
> > > mocha-developer at rubyforge.org
> > > http://rubyforge.org/mailman/listinfo/mocha-developer
> > >
> > _______________________________________________
> > mocha-developer mailing list
> > mocha-developer at rubyforge.org
> > http://rubyforge.org/mailman/listinfo/mocha-developer
> >
> _______________________________________________
> mocha-developer mailing list
> mocha-developer at rubyforge.org
> http://rubyforge.org/mailman/listinfo/mocha-developer
>


More information about the mocha-developer mailing list