Hi,
today I tried to fix a bug (http://jira.codehaus.org/browse/GEOT-1693)
that required fixing DefaultFeatureResults and co. The issue with this
bug is that one cannot unit test DefaultFeatureResults without
creating a ton or related classes... unless mock testing is used.

So I gave a spin at EasyMock 2 and... wow! Look at how simple the
test with the mock object is:

public void testMaxFeatureOptimized() throws Exception {
     DefaultQuery q = new DefaultQuery("roads");
     q.setMaxFeatures(10);

     // mock up the feature source so that it'll return a count of 20
     SimpleFeatureType type = DataUtilities.createType("roads", 
"_=the_geom:Point,FID:String,NAME:String");
     FeatureSource fs = createMock(FeatureSource.class);
     expect(fs.getSchema()).andReturn(type).anyTimes();
     expect(fs.getCount(q)).andReturn(20);
     replay(fs);

     DefaultFeatureResults results = new DefaultFeatureResults(fs, q);
     assertEquals(10, results.size());
}

Basically I create a mock, set a few expectations on the method
calls and their return values, and I'm in business. Lovely.

Unfortunately this did not last long. I had to make a similar
fix in JDBCFeatureCollection, which needs JDBCFeatureSource,
which in turn is not an interface. And EasyMock + JUnit 3
does not allow to mock interfaces... Junit4 is required to
do so.

I looked around, JMock is there, but imho setting up
the mock objects is quite a bit more convoluted.
JUnit4 is apparently supported by both Eclipse and Maven,
yet I'm a little reluctant upgrading due to the extensive
amount of tests made using JUnit 3... we have no complaints
on it and we have a good expertise grown on it...

Soo... what do people think? Opinions?
Cheers
Andrea

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Geotools-devel mailing list
Geotools-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/geotools-devel

Reply via email to