How to align TDD with SUT interface contracts?

Assuming that we are implementing a Stackclass using TDD , we will need to add a new test for each bit of the functionality of our Stack class that uses 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 executing Unit-Tests, you should focus on what external behavior our class should perform, so the Unit-Tests collection checks the execution of all expected contracts for my Stack interface.

My question is how to reconcile these two aspects.

For example, if my Stackinternal uses an array with an initial size of 8, I want it to grow if my user wants to insert the 9th element. To add resizing functionality, I want to have at least one test that manages my class code in that direction (am I right?).

On the other hand, it will add Unit-Test (or is it not Unit-Test?), Which does not fulfill the actual class contract (I assume that the user does not care about the internal implementation of the stack), but its implementation.

So, we have a twist that I don’t know how to solve. Am I confusing something here?

thank

Edit

After much searching, I came to the following link, which seems to be regarding this issue: http://stephenwalther.com/blog/archive/2009/04/11/tdd-tests-are-not-unit-tests.aspx

+3
3

, . , . 9 , Stack .

TDD API. . 8 2 - , . , (, std::vector). , Stack, , 8 Should_Not_Error_When_Push_More_Items_Than_Initial_Size.

+4

, - , TDD . TDD , api . , , - ( ).

, , , . - , , ( )

+1

:

  • , .
  • , .

, , , . ! , , mocks ( , ).

I found this a useful technique for synchronization, streaming, or something else that encapsulates internal behavior that may not necessarily be visible from the outside. Of course, you sacrifice success to some extent. If this is important, just worry about the behavior of the stack in terms of its calling class and use the results of system performance and profiling to pick up the rest.

0
source

Source: https://habr.com/ru/post/1762352/


All Articles