White Box Testing
Test your code
   Home      TestPattern-CollectionManagementPatterns
Author -  Marc Clifton
Marc is the creator of two open source projets, MyXaml, a declarative (XML) instantiation engine and the Advanced Unit Testing framework, and Interacx, a commercial n-tier RAD application suite.  Visit his website, www.marcclifton.com, where you will find many of his articles and his blog.
Marc lives in Philmont, NY.


Collection Management Patterns

A lot of what applications do is manage collections of information.  While there are a variety of collections available to the programmer, it is important to verify (and thus document) that the code is using the correct collection.  This affects ordering and constraints.

The Collection-Order Pattern

This is a simple pattern that verifies the expected results when given an unordered list.  The test validates that the result is as expected:

  • unordered
  • ordered
  • same sequence as input

This provides the implementer with crucial information as to how the container is expected to manage the collection.

The Enumeration Pattern

This pattern verifies issues of enumeration, or collection traversal.  For example, a collection may need to be traversed forwards and backwards.  This is an important test to perform when collections are non-linear, for example a collection of tree nodes.  Edge conditions are also important to test--what happens when the collection is enumerated past the first or last item in the collection?

The Collection-Constraint Pattern

This pattern verifies that the container handles constraint violations: null values and inserting duplicate keys.  This pattern typically applies only to key-value pair collections.

The Collection-Indexing Pattern

The indexing tests verify and document the indexing methods that the collection container must support--by index and/or by key.  In addition, they verify that update and delete transactions that utilize indexing are working properly and are protected against missing indexes.