Nate's Programming Blog

There are some that say that unit tests should be the fundamental base testing strategy for any class that you write and that integration tests should be developed on top of those unit tests. I understand the reasoning behind this idea, but I feel in some cases creating a unit test just doesn’t make all that much sense. For instance, in the current application I am working on I have a client service that connects to a webservice to query domain and reporting information. It doesn’t make a lot of since to create some elaborate mock object to simulate connecting to this service when the only purpose of my service is to make this connection. I have other objects that I use to generate the query object and parse the response objects, so I wouldn’t be unit testing that functionality here. It is simply connecting to the service passing it an already constructed query object and then just feeding the result back to the calling function. I believe in this situation it only makes since to do an integration test, since in essence this class’s purpose is integration. What would I accomplish with a unit test? What would a unit test tell me about how this class functions?

I also look at DAOs in the same way. The purpose of a dao is to connect and retrieve or update information in some resource. If you mock out that resource you are only testing your connecting to some mock object which I don’t believe gives you any information about how this class is going to function when you connect to the actual resource. Now if you followed some bad coding design and had business logic mixed in with your DAO, then I can understand the need for a unit test, but if you are simply doing an add, update, delete or query what is the purpose.


This entry was posted on Monday, June 20th, 2005 at 8:37 pm and is filed under Programming. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
2 Comments so far

  1. James on June 21, 2005 6:38 am

    Maybe you can tell you mock that it should fail on the next call…then you can see how your dao would handle a db going down.

  2. Nate on June 21, 2005 11:54 am

    That makes since, but typically I’m just going to throw some runtime exception up the chain if the db goes down. What else are you going to do in that situation, so do I really need to test that? The other possiblity is to test that the correct exception gets thrown if you try and insert a record twice or something like that. That makes a little more since to me. Maybe the dao isn’t a good example, but definately the service, because I’m not changing the data on the resource, just querying it.

Name (required)

Email (required)

Website

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

Feel free to leave a comment

top