Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I'm a huge fan of unit testing, but still make use of a FGDB to grab features for running unit tests against when using the ArcObjects framework.

Is anyone successfully using mocking against thinks like IFeature, IGeometry, IWorkspace etc. If so, I'd love to see some examples of how you're doing it. I don't really care about what mocking framework you use, just seeing how you're doing it would be greatly appreciated.

The problem I see is that you're having to slice and dice between so many interfaces on the same object, that the overhead of creating a representative mock object would be huge.

share|improve this question
    
For anyone else that may not know about Mocking (like me), please see this link. Interesting stuff. stackoverflow.com/questions/300177/… –  Simon Aug 23 '10 at 11:19
add comment

2 Answers

We have, on a large project, managed quite well to isolate ArcObjects code from our business logic. That is generally the way to go, I'd say, rather than attempting to mock it all out, even if it is possible using mocking frameworks to get some of the way.

Ask yourself, Why it is you feel the need to mock. Typically, it is because of a missing abstraction. Think small responsibilities and minimize the surface of the huge, ugly ArcObject monster. Avoid dragging around ArcObject types just because some aspect of them is needed somewhere.

I can give one concrete example from our project. A portion of the code seemed to depend on IMxDocument. It turned out the only reason was that the active view needed to be refreshed. So we created an IViewRefresher interface instead and only worked on that; easy to mock and test. Additionally, it makes the intent of the code much clearer and removes the temptation for someone to start doing funny things with the IMxDocument that they weren't supposed to do because all we wanted to do here was refresh. The same exercise can be done with a lot of the ArcObjects code.

Also, we wrapped all access to feature classes in type safe wrappers, again providing mockable code shielding the business code from ArcObjects.

We've discussed not even using the geometry types of ArcObjects, but currently we do allow those interfaces to be used directly in our code. (However, interface knowledge only is allowed and all instantiations of geometries use our own geometry factory.)

In summary, I'm not disencouraging mocking but I'd encourage mocking at a different level of abstraction than ArcObjects.

share|improve this answer
    
great answer Cumbayah. I also have a lot of dificulties unit testing AO code. The example you gave was great (IViewRefresher) and I might apply that to my work here. Can you give further examples? –  George Aug 23 '10 at 15:43
    
Thanks Cumbayah. This is what I currently do on medium to large projects, creating a separate assembly to abstract all AO implementation. It's this abstraction I'd like to test without resorting to stored data though, be it XML workspaces or geodatabases of one sort or another. I find that from time to time with different data, new issues crop up, which then need to have tests created for, which necessitates additional test data. Over time I have so much test data for all test cases, that the projects become huge to manage and move around, let along download by my automated build server. –  BlinkyBill Aug 24 '10 at 3:45
    
Cumbayah, this sounds incredible. I would love to some examples. Have you ever considered presenting something on this subject at one of the ESRI conferences? I think the ESRI/GIS community is dying for this kind of stuff. Would love to see some open source movement get started for testing/mocking ArcObjects. –  Keith G Dec 17 '10 at 19:16
    
This is an old topic I understand, but any chance we can get a sample of your "own geometry factory"? I'm trying to get my organization moved in the direction of unit testing, but I'm getting hung up on the ArcObjects monkey. –  Luke Jul 30 '12 at 15:08
add comment

Unit Testing for Esri Developers by Dave Bouwman and Brian Noyle is a pretty good starting place - particularly since they threw out some code to look at.

share|improve this answer
    
Thanks for the pointer bwreilly. What Dave does though is simply use XML representations of features. So while it's helping, it still relies on storing data for tests, which is what I'm trying to get away from. –  BlinkyBill Aug 24 '10 at 3:47
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.