That's indeed very cool Andrea.
I've to say, to support Andrea's proposal, that I've been using 
junit4+EasyMock for some time now on another project and its going perfectly,  
and indeed provides for a true way of isolating unit tests, and helps design 
testable code, etc.
Yet, I don't quite understand why EasyMock wouldn't be able to mock up 
interfaces if using Junit 3, they seem unrelated to me, yet never tried to 
use easymock with Junit 3.
Though I know by this time Andrea sent an email to the author to confirm.

Gabriel

On Monday 28 January 2008 03:32:51 pm Andrea Aime wrote:
> 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
>
> !DSPAM:4045,479de7c9156802458217002!



-------------------------------------------------------------------------
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