You are viewing a plain text version of this content. The canonical link for it is here.
Posted to adffaces-dev@incubator.apache.org by John Fallows <jo...@gmail.com> on 2006/05/11 00:23:56 UTC

Thoughts about unit testing and mock objects

The recent delivery ADF Faces codebase with the missing jsf-mock dependency
got me thinking...

   - "Do we really need hand-written (or possibly generated) mock
   implementation classes as a dependency?"
   - "What strategy should we follow for our own classes that require
   mock implementations?"

For future test development, we might benefit from using jMock which doesn't
require a separate set of mock class implementations to mock the interfaces
/ abstract classes.

http://jmock.codehaus.org/getting-started.html

Interestingly, jMock can leverage CGLib to manage dynamic proxy creation of
abstract classes, and produces extremely readable unit tests that capture
the semantics of the code being tested.

Does anyone have jMock or mock object experiences to share?

tc,
-john.
--
http://apress.com/book/bookDisplay.html?bID=10044
Author: Pro JSF and Ajax: Building Rich Internet Components, Apress

Re: Thoughts about unit testing and mock objects

Posted by Craig McClanahan <cr...@apache.org>.
On 5/12/06, John Fallows <jo...@gmail.com> wrote:
>
> On 5/12/06, Craig McClanahan <cr...@apache.org> wrote:
>
> > On the surface, it would appear so, but IANAL and never played one on
> TV.
>
>
> I had to read that several times to figure it out - does IANAL mean "I Am
> Not A Laywer" ? :-)


Right the first time :-).  It's a pretty common acronym when discussing
arcane subjects like licensing on open source lists, because nobody wants to
have someone come back later and try to sue you for giving legal advice.

Of course, for me it does evoke a small personal smile when *I* use this
acronym, because my father is, in fact, a lawyer :-).

Craig

Re: Thoughts about unit testing and mock objects

Posted by John Fallows <jo...@gmail.com>.
On 5/12/06, Craig McClanahan <cr...@apache.org> wrote:
>
> On 5/12/06, John Fallows <jo...@gmail.com> wrote:
> >
> > On 5/10/06, Adam Winer <aw...@gmail.com> wrote:
> > >
> > > JMock does look interesting, but a couple of basic questions:
> > > - Is it available in a maven repository?
> >
> >
> > Yes.  http://www.ibiblio.org/maven2/jmock/
> >
> > - Is its license compatible?
>
>
> On the surface, it would appear so, but IANAL and never played one on TV.


I had to read that several times to figure it out - does IANAL mean "I Am
Not A Laywer" ? :-)

The way to get a definitive answer is to submit this to the
> legal-discuss@apache.org mailing list where license-savvy folks are
> hanging
> out.  I'll forward them a query.


Thanks, that'll be useful to know.

CGLib is under Apache2 license and jMock is under the following license
> >
> > http://jmock.codehaus.org/license.html
> >
> > ... and one more general one.  The thing that drives me up the
> > > wall with the current mock codebase in the ADF Faces tests
> > > is that it forces you to say "I expect method foo() to be called
> > > at least N times", even though with JSF there's rarely any
> > > such assurances whether a method will be called or not,
> > > and if so how many times.   E.g., how often is
> FacesContext.getViewRoot
> > ()
> > > called?  Once?  Twice?  20 times?
> >
> >
> > As the test writer you have the flexibility to either specify the number
> > of
> > calls precisely or not, depending on whether or not it is important to
> the
> > test.
>
>
> I think Adam's point was that the number of calls might be indeterminate
> if
> different implementations of JSF do things differently.  On the other
> hand,
> I wouldn't want to use a library that *forced* me to specify call counts,
> even when I didn't care, either :-).


Yep.  Sorry if I wasn't clear, jMock doesn't force you to specify call
counts.

tc,
-john.

-- 
http://apress.com/book/bookDisplay.html?bID=10044
Author: Pro JSF and Ajax: Building Rich Internet Components, Apress

Re: Thoughts about unit testing and mock objects

Posted by Craig McClanahan <cr...@apache.org>.
On 5/12/06, John Fallows <jo...@gmail.com> wrote:
>
> On 5/10/06, Adam Winer <aw...@gmail.com> wrote:
> >
> > JMock does look interesting, but a couple of basic questions:
> > - Is it available in a maven repository?
>
>
> Yes.  http://www.ibiblio.org/maven2/jmock/
>
> - Is its license compatible?


On the surface, it would appear so, but IANAL and never played one on TV.
The way to get a definitive answer is to submit this to the
legal-discuss@apache.org mailing list where license-savvy folks are hanging
out.  I'll forward them a query.

CGLib is under Apache2 license and jMock is under the following license
>
> http://jmock.codehaus.org/license.html
>
> ... and one more general one.  The thing that drives me up the
> > wall with the current mock codebase in the ADF Faces tests
> > is that it forces you to say "I expect method foo() to be called
> > at least N times", even though with JSF there's rarely any
> > such assurances whether a method will be called or not,
> > and if so how many times.   E.g., how often is FacesContext.getViewRoot
> ()
> > called?  Once?  Twice?  20 times?
>
>
> As the test writer you have the flexibility to either specify the number
> of
> calls precisely or not, depending on whether or not it is important to the
> test.


I think Adam's point was that the number of calls might be indeterminate if
different implementations of JSF do things differently.  On the other hand,
I wouldn't want to use a library that *forced* me to specify call counts,
even when I didn't care, either :-).

Craig

Re: Thoughts about unit testing and mock objects

Posted by John Fallows <jo...@gmail.com>.
On 5/10/06, Adam Winer <aw...@gmail.com> wrote:
>
> JMock does look interesting, but a couple of basic questions:
> - Is it available in a maven repository?


Yes.  http://www.ibiblio.org/maven2/jmock/

- Is its license compatible?


CGLib is under Apache2 license and jMock is under the following license

http://jmock.codehaus.org/license.html

... and one more general one.  The thing that drives me up the
> wall with the current mock codebase in the ADF Faces tests
> is that it forces you to say "I expect method foo() to be called
> at least N times", even though with JSF there's rarely any
> such assurances whether a method will be called or not,
> and if so how many times.   E.g., how often is FacesContext.getViewRoot()
> called?  Once?  Twice?  20 times?


As the test writer you have the flexibility to either specify the number of
calls precisely or not, depending on whether or not it is important to the
test.

This leads to extremely brittle tests that are a mess to write
> and understand.
>
> So, to be more brief:  does JMock fix this awfulness, or perpetuate
> it? :)


I believe it makes things better than our approach with the old jsf-mock
objects.

tc,
-john.

On 5/10/06, John Fallows <jo...@gmail.com> wrote:
> > The recent delivery ADF Faces codebase with the missing jsf-mock
> dependency
> > got me thinking...
> >
> >    - "Do we really need hand-written (or possibly generated) mock
> >    implementation classes as a dependency?"
> >    - "What strategy should we follow for our own classes that require
> >    mock implementations?"
> >
> > For future test development, we might benefit from using jMock which
> doesn't
> > require a separate set of mock class implementations to mock the
> interfaces
> > / abstract classes.
> >
> > http://jmock.codehaus.org/getting-started.html
> >
> > Interestingly, jMock can leverage CGLib to manage dynamic proxy creation
> of
> > abstract classes, and produces extremely readable unit tests that
> capture
> > the semantics of the code being tested.
> >
> > Does anyone have jMock or mock object experiences to share?
> >
> > tc,
> > -john.
> > --
> > http://apress.com/book/bookDisplay.html?bID=10044
> > Author: Pro JSF and Ajax: Building Rich Internet Components, Apress
> >
> >
>



-- 
http://apress.com/book/bookDisplay.html?bID=10044
Author: Pro JSF and Ajax: Building Rich Internet Components, Apress

Re: Thoughts about unit testing and mock objects

Posted by Adam Winer <aw...@gmail.com>.
JMock does look interesting, but a couple of basic questions:
 - Is it available in a maven repository?
 - Is its license compatible?

... and one more general one.  The thing that drives me up the
wall with the current mock codebase in the ADF Faces tests
is that it forces you to say "I expect method foo() to be called
at least N times", even though with JSF there's rarely any
such assurances whether a method will be called or not,
and if so how many times.   E.g., how often is FacesContext.getViewRoot()
called?  Once?  Twice?  20 times?

This leads to extremely brittle tests that are a mess to write
and understand.

So, to be more brief:  does JMock fix this awfulness, or perpetuate
it? :)

-- Adam


On 5/10/06, John Fallows <jo...@gmail.com> wrote:
> The recent delivery ADF Faces codebase with the missing jsf-mock dependency
> got me thinking...
>
>    - "Do we really need hand-written (or possibly generated) mock
>    implementation classes as a dependency?"
>    - "What strategy should we follow for our own classes that require
>    mock implementations?"
>
> For future test development, we might benefit from using jMock which doesn't
> require a separate set of mock class implementations to mock the interfaces
> / abstract classes.
>
> http://jmock.codehaus.org/getting-started.html
>
> Interestingly, jMock can leverage CGLib to manage dynamic proxy creation of
> abstract classes, and produces extremely readable unit tests that capture
> the semantics of the code being tested.
>
> Does anyone have jMock or mock object experiences to share?
>
> tc,
> -john.
> --
> http://apress.com/book/bookDisplay.html?bID=10044
> Author: Pro JSF and Ajax: Building Rich Internet Components, Apress
>
>