TDD with strategy template

I am trying to implement a strategy template using TDD. Each element of the strategy implements an interface. What is the best way to do this using TDD?

Do you need to create a test device for each implementation of an interface testing the same methods, but in each implementation?

Any articles containing a detailed approach to adoption would be greatly appreciated :)

+4
source share
2 answers
  • Record a test that does not work
  • Write an ugly code to pass this test
  • Refactoring to improve code

In step 2, write code that does not implement the strategy template (the simplest thing that works even if duplicate code is present).

Then, in step 3, you reorganize each class one at a time into a strategy template, if that makes sense.

If you really do TDD, you are not starting with the template - you are reorganizing it.

+2
source

I think I would write a separate test class for each implementation of the strategy.

You can make an abstract class for everyone to inherit. This will help you make sure that you run all the tests for each strategy, but it has a small drawback in that you have to implement stub methods, at least before each test class even compiles.

+1
source

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


All Articles