So, my colleague and I have a very heated debate. We are starting a new project and we are trying to use BDD. We are both pioneers and do not quite understand what methods should be used. We have written some specifications, and now we are implementing the code. Everything becomes quite complicated, as there is a lot of interaction with databases. We focus on how to mock our data. The method we were going to would require us to mock our methods instead of our data. This is easiest if I show you the code ...
public static void AssignLeadToDistributor(int leadId, int distributorId) { Lead lead = GetById(leadId); lead.DistributorId = distributorId; Save(lead); }
Basically, we would have to override GetById () and Save () in order to return us our data in order to verify this. It seems to make sense to do it like this:
public static void AssignLeadToDistributor(Lead lead, Distributor distributor) { lead.DistributorId = distirbutor.Id; }
Then we could just make fun of our objects.
Clearly, the second method simplifies testing. However, the argument is that we do not want to get a new lead and distributor object on our front-end code, because it would be easier to just pass the identifiers of our objects. Reduction of the actual code in our interface.
I hope I explained it quite well.
What do you guys think? Which way makes sense?
unit-testing tdd mocking specifications bdd
Kevin wiskia
source share