Automated Unit Tests in my life – Part 6

Should ability of testing affect the design of the production code?

The tests code should be same high quality as implementation code.
But what if the development code should be changed in order to be able to write tests?
Sometimes there are situations when it is impossible to write a test without changing our genuine design.
Here is a simple example. Let’s say that our tested class uses some internal Data Provider, which brings the data from data storage (could be Data Base). We want a “clean” test for our class, which is not dependent of uses DataProvider.
Meaning we will get data from other object, which replaces DataProvider and Data Base. They call objects like this Mock Objects or Mocks… But we will talk about these in later parts.

In this situation in order perform a unit test we can do 2 things:
1) We should create a public property that uploads data
2) We might have some flag, which will indicate to use some fake DataProvider (Mock Data Provider) and use it in tests

So we have to change our production code only in order to Unit Test it…(Familiar situation?).
There could be millions of reasons that we do not want to change our genuine code in order to test it!!!
So, how do we solve the problem?
As you know problem has solution. Mocking Frameworks can solve this problem.