Make stuff to do things

Subscribe (?) Subscribe to RSS

Posts Tagged ‘functional testing’

The importance of unit testing and functional testing

Published on July 1st, 2009 in Comments

I recently read a blog article, Benefits of automated functional testing, which included a section arguing that unit testing was not as important as functional testing. I agree that functional testing is important (and the author provides several good arguments for it) but I am concerned about the negativity against unit testing. The author makes the following argument in favor of functional testing which I think is a great argument in favor of all testing:

The complexity that does arise in this kind of software is all down to interactions between components, messy and changing business requirements and how the whole blob integrates at runtime.

I think the “interactions” issue is one that can be addressed by unit tests. The interaction between components boils down to one component making a request of another component; for example calling a method with an agreed upon set of arguments. The requesting component will have an expectation for the return of the method. If the called method does not meet the expectations of the request then a failure will occur. Unit tests can be used to verify that a method returns in an expected way.

With unit tests in place developers can confidently re-factor their code knowing that any violated expectations will be revealed when running those tests. It would be nice to account for every possible scenarios and test for every fringe case but that is unrealistic. Unit tests can be used to make an agreement with other developers saying “this code will do A when given B at all times”; developers are free to go outside the bounds of these expectations but do so knowing that their use of that unit of code is untested.

I’ve been sitting on a draft of a post regarding the importance of both functional and unit testing. I’ve included it below:

I’ve been thinking about a way to explain the importance of both functional and unit testing. I’ve been trying to come up with an appropriate analogy and have settled on the following:

Let’s imagine a particular software application is a physical structure such as a bridge. The materials used in the construction of the bridge are analogous to the units of a software application. The shape of the bridge is analogous to the functional operations of a software application.

When determining the strength of a bridge, the shape of the bridge plays a significant role, however, a determination of strength is not complete without knowing the material being used to construct the bridge.

Unit tests measure the quality of material used to build the application.

Functional tests measure the strength of the application structure.

The overall quality of the application is dependent on both.

Switch to our mobile site