Unit Testing a Linked List

I believe integration tests are the most valuable type of automated test. A linked list is usually part of a standard library, so that makes it a great example of a candidate for integration testing.

My guideline is, “one test per requirement.” For example, for a Linked List, I would probably start with one test for each of the following:

1) Can values be prepended, 2) inserted at a given index, and 3) appended?

4) Can values be removed without compromising the list’s integrity?

5) Can the list be traversed forward and (for doubly linked lists), 6) backward?

7) Are we preventing out-of-bounds access?

8) Any potential type safety requirement

9+) Each potential memory efficiency requirement

…) Each potential runtime requirement

Leave a Comment