I am trying to follow TDD and I ran into a little problem. I wrote a test to insert a new user into the database. Insert a new user is called in the MyService class, so I went ahead and created mytest. This failed, and I started implementing my CreateUser method in my MyService class.
The problem I am facing is that MyService will go to the repository (another class) to perform the database insert.
So, I decided that I would use a mocking structure to mock this repository class, but is this the right way?
That would mean that I would have to modify my test to actually create a layout for my user repository. But is it recommended? At first I wrote my test and made it unsuccessful, and now I understand that I need a repository and I need to mock it, so I need to change my test to serve the mocking object. Smell a bit?
I would like some feedback here.
If so, when will I create a real user repository? Will it need its own test?
Or should I just forget the mockery of something? But then it will be classified as an integration test, not a unit test, as I will test MyService and User Repository together as a unit.
I lost a little; I want to start the right path.
source share