[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [stellation-res] Something helpful for writing tests...
|
Mark C. Chu-Carroll wrote:
Just found this while doing some web-browsing. It's a very neat idea
called mock objects for helping to write unit tests for complex
systems. There's a very nice looking implementation of it for JUnit
called JMock, at jmock.org, which is distributed under a very friendly
BSD style license. There's also a very short tutorial there to give
you the sense of what mock objects are for, at
http://jmock.org/getting-started.html.
I think this could make our lives significantly easier when it comes
to a lot of the kinds of testing
that we really need to do.
I happen to be an user of jMock for about one month and I must say that
it really brought my testing to a new level! Now I'm able to do proper
unit tests, testing one class at a time.
I have a little tip that'll hopefuly save you a bit of frustration:
org.jmock.Mock can mock only interfaces. If your code is not
interface/implementation separated, there is an extension that enables
you to mock concrete classes too (they need to have protected or public
no-arg constructor for that), it's in extensions/cglib in jMock source.
If you wish to take a look at more examples of jMock usage, here's my
project's base testcase (jMock stuff at the bottom):
http://objectledge.org/viewcvs.cgi/ledge-components/src/main/java/org/objectledge/utils/LedgeTestCase.java?rev=HEAD&content-type=text/vnd.viewcvs-markup
And here's one of my jMock unit tests:
http://coral.objectledge.org/viewcvs.cgi/coral-maven-plugin/src/test/java/org/objectledge/coral/tools/generator/model/ResourceClassTest.java?rev=HEAD&content-type=text/vnd.viewcvs-markup
Other tools that I find extremely useful are Clover - test coverage
reportnig tool (commercial, but OS projects are granted gratis
licenses), example report:
http://objectledge.org/modules/ledge-components/clover/index.html
And Maven itself, unfortunately there is no plugin for generating
Eclipse plugins, features and update sites that I know of, so it may be
not so useful to you, example report:
http://objectledge.org/modules/ledge-components/
R.