Small Is Beautiful
Now This Is Micro!
We've ruled an elephant
Rest assured, we are not going to write 11 microtests for this simplistic class.
In fact, experienced microtesters don't always zoom their lens onto the class this much.
We will consider the interesting combinations as well as reduce similar cases.
TestList()
out,
as well as a test of the entire Add()
method.
When we drill even deeper down, we get to the micro-behavior level. On this
level we start considering combinations of method execution paths and data contexts.
We can identify at least these combinations:Execution Path | Data Context | Micro-Behavior |
---|---|---|
Add( element E) | an empty List | place E in the list |
Add( element E) | a List with one element X | place E after X |
Add( element E) | a List with two elements, X followed by Y | place E after X and Y |
Add( element E) | a List with INITIAL_CAPACITY elements | grow the list (retain element order), place E last |
this[ low index] | an empty List | throws ArgumentOutOfRangeException |
this[ negative index] | a non-empty List | throws ArgumentOutOfRangeException |
this[ high invalid index] | a non-empty List | throws ArgumentOutOfRangeException |
this[ valid index] | a non-empty List | return the element |
this[ high valid index] | a List that grew | return the element |
Empty | an empty List | return true |
Empty | a non-empty List | return false |
(Pssst: can you sense now why the term "unit test" might communicate something on a different level?)
(Reading...)
Formatting Hints:
To format... | use this markup: |
---|---|
source code | {source:lang=java|lineNumbers=false}...{source} (Supported languages: java, cpp, csharp, c, python.) |
bold text | __some text__ |
italicized text | ~~some text~~ |
underlined text | @@some text@@ |
a method or class name | ``myMethod(...)`` |