How should we setup up complex situations for tests?
Posted
by ShaneC
on Stack Overflow
See other posts from Stack Overflow
or by ShaneC
Published on 2010-03-08T22:08:27Z
Indexed on
2010/03/08
22:21 UTC
Read the original article
Hit count: 284
integration-testing
|testing
I'm currently working on what I would call integration tests. I want to verify that if a WCF service is called it will do what I expect.
Let's take a very simple scenario. Assume we have a contract object that we can put on hold or take off hold. Now writing the put on hold test is quite simple. You create a contract instance and execute the code that puts it on code.
The question I have comes when we want to test the taking off hold service call. The problem is that putting a contract on hold can be actually quite complicated leading to various objects all be modified. So usually I would use the Builder pattern and do something like this..
var onHoldContract = new ContractBuilder().PutOnHold().Build();
The problem I have with this is now I have to pretty much replicate a large part of my put on hold service. Now when I change what putting something on hold means I have two places I have to modify.
The other option that immediately jumps out at me is to just use the put on hold service as part of my test setup but now I'm coupling my test to the success of another piece of code which is something I don't like to do since it can lead to failures in one spot breaking unrelated tests elsewhere (if put on hold failed for example).
Any other options I'm missing out here? or opinions on which method is preferable and why?
© Stack Overflow or respective owner