Assuming we are implementing using TDD a Stack
class, we would need, for each bit of functionality of our Stack class, to add a new test that exercises it:
[TestMethod] public void Should_Be_Empty_After_Instantiation()
[TestMethod] public void Should_Not_Be_Empty_After_Pushing_One_Item()
...
Now, on the other hand, when doing Unit-Tests, one should focus on what external behaviour our class is supposed to provide, so the set of Unit-Tests check that all the expected contracts for my Stack interface are fulfilled.
My question is in how to conciliate those two aspects.
For example, assuming my Stack
uses internally an array with an initial size of 8, I'll want it to grow if my user wants to insert a 9th item. For adding that resizing functionality, I'll want to have at least one test that drives my class code in that direction (am I right?).
On the other hand, that would be adding a Unit-Test (or isn't this really a Unit-Test?) that exercises not the actual contract of the class(I am assuming the user doesn't care for the internal implementation of the Stack) but its implementation.
So we have a twist here, that I don't know how to solve. Am I making any confusion of concepts here?
Thanks
Edit
After much googling I came to the following link that seems to deal with this issue: http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx
I would say they are the same thing when refering to TDD and external behaviour of a particular class. When writing TDD style code you are focusing on what the behaviour is when using the public api of the class. So your first two test cases are correct since they test something public on the class (size of stack).
As for internal implementation and whether you use an array, the test is not concerned with how it is done, just that the functionality works against the given test. You may choose to implement it differently at a later stage and your tests will verify that the behaviour remains unchanged (tests don't fail after the refactor)