Sunday, November 13, 2011

Unit Testing


What Is a Unit?

From a regulatory perspective, the device manufacturer 
can define a unit to be any grouping of source code.  
However, the definition of a unit for unit testing 
generally should be done at the smallest, most practical 
code level.
A unit can be defined as a single function, group of 
related functions, or an entire file of functions to verify 
the code is in relative isolation.  The most traditional 
approach is to define a unit to be at the funtion level 
ensuring that each function behaves properly and the 
design was implemented correctly.  In cases where there 
are groups of related functions, testing can be done on 
the set of functions and related data.  For classes, one 
possible decision is to apply unit tests to every public 
method, since the private methods will inherently be 
covered as part of the object-oriented hierarchy.  By 
testing at the higher levels and stubbing out fewer 
internal functions, code can easily be refactored by the 
developer, without wholesale changes to the unit tests 
that cover them.  Care should be given not to test at too 
high a level, it is possible to lose some control if the
 testing tries to encompass too many functions at once

White-box testing is based on internal structure.  Unit
testing is a form of whitebox testing that is done at or
near the code level to ensure that the implementation
matches the intended design.  The design must be
documented in sufficient detail so that tests can

be developed to verify the accuracy of the software
implementation.  The idea is to test that small sections
of code (typical functions) work as intended and are
reasonably robust.  Once these individual code blocks
are tested, larger groups of those building blocks will
hold up better during integration.
The execution of a unit test should be as fully automated
as possible and should be given strict pass/fail criteria
based on the intended design.  Unit test configurations
often allow batching or scripting of tests to be run. The
testing tries to encompass too many functions at once.




0 comments:

Post a Comment