Flag This Hub

Software Unit Testing

By


One of the most important aspects of testing computer software is that the earliest you can find an error or bug, then the easier and cheaper it is to fix. There is no earlier opportunity to resolve such a problem, then directly after a developer has written the code. This sort of testing is called Unit Testing, and although a development team may be responsible for conducting it, unit testing is an important part of any quality assurance test plan.

 

Computer programs that are written to solve any none trivial task, can be very complex in their design. Many routines, objects and methods can be employed to conduct simple tasks that may be difficult to map back to the original specification. When these simple tasks are joined together to form the final application, an error in any one, may be presented in numerous places, and be difficult to track down. With object orientated languages (c++, c# and java to name just a few) object inheritance, factories and templates can make this process even more difficult. Unit testing takes the approach of identifying the smallest possible ‘unit’ of testable code and writing a test case for it. These sections of code are normally single routines or object methods, which will likely only have a program code interface, rather than a user GIU. For this reason detailed programming knowledge is required, both of the language used, and the environment (internal program structure, libraries etc). This prevents a normal test team from defining, scripting and conducting such tests. Rather, it is integrated into the actual programming cycle. This integration has a number of advantages, but also disadvantages as well.

One of the most notable advantages is the inherent ability to automate unit testing. As the tests can only be conducted at code level, the tests themselves can be integrated into the build process – i.e. every time a build is made, the unit tests are run. There are a number of automation tools that can be used to do this – junit for java, and cunit for c/c++. Use of these libraries can help not only in the writing of the tests, but also the automation and test reporting. There are a number of resources on the Internet that a worth checking for more detailed information regarding this.

 

If unit tests are conducted correctly, perhaps the majority of bugs will be discovered and fixed before the code gets anywhere near the qa team. This helps drive up quality, and drive down costs. However, there are some obstacles to overcome before he full advantage can be obtained.

 

One major problem is down to experience. Developers may have limited knowledge of how to write complete test cases. This is not too suppressing, as it is something that is normally left to the test team. If a routine/object/method is not tested fully, then there is a real possibility of easily captured bugs slipping through, and being far more difficult to fix later. It is also normal for developers to write their own unit tests. This introduces the problem that if a developer miss codes a function, then they may also miss test the function. It is far better for developers to write each other’s tests.

 

The main organisational problem can be down to miss management. Too often project management do not understand the importance of unit testing. Inevitably, projects can slip and deadlines loom with efforts made to cut out anything that may not be needed. Unit testing is a key target for this. However, as mentioned above, it’s purpose is to find errors quickly – if they are not found in unit testing, they may be found later, and be much more expensive and time consuming to fix.

 

There are a number of development methods that rely heavily on automated unit tests. Most notable of these is Agile, which uses these tests as the actual documentation for the code. It promotes the method of test first, then code.

 

In summary

 

  • Unit testing is an important part of any modern software quality assurance plan.
  • Unit tests should be conducted by the development team.
  • It is best if developers don’t test their own code.
  • Automating tests into the software build process ensures that all tests are run with each new build of code.
  • If time scales are tight, it is a false economy to cut unit testing, it only increases costs further down.

Comments

No comments yet.

Submit a Comment
Members and Guests

Sign in or sign up and post using a hubpages account.



    Like this Hub?
    Please wait working