I totally believe in not repeating yourself in production code. I've accepted the idea that you shouldn't repeat yourself within test code. But what happens when you have production services that would simplify test code?
Let me pose an example. We have a service that accesses the Doohickey API. The Doohickey API is complex, by necessity, and we have a bunch of code to simplify it for our needs.
Now I need to write some automated tests for our service. My tests need to set up data in the service and it would be really handy to reuse that facade. But then I get into an argument with myself, that goes roughly like this:
"If you introduce a bug in the Facade, the test might not show it."
"But, if you just take a copy, then when Dohickey Inc upgrade their API, you need to make the change in two places."
"True, but maybe that's a good thing. We can upgrade production code first, manage test data using the old, known, still-supported API and test the new version thoroughly."
And then I think maybe I'm overthinking the problem. Does anyone have experience with this kind of issue? If so, which way did you go, and did you regret it at all later?
Edit: Early comments suggest a more specific example is required.
Say I have a service that can create a product AND create an order. I have the following test to write ...
Given that product X exists When customer Y orders product X Then an order should exist for customer Y, including only product X
For the "When" part of this, I contact my service, which uses a facade around the Dohickey Purchasing API to create the order.
The "Given" and "Then" steps should create a product and get an order, but they shouldn't go through the service to do so. Perhaps my service doesn't have that functionality, and if it does then I will test it elsewhere.
BUT the facade that lives within the service would make the test code much simpler. So should I reference the production code and use it or copy / rewrite the facade?