The simplest solution to this is to not have different names on the prod and test databases.
If you're stuck with both db's on the same server/instance (for whatever reason), do use search and replace.
It will make your life easier.
The path down dynamic SQL lane has been regretted by many - it should never be anyone's first choice.
Personally, I would never go there for the above reasons.
...just my .02 of course
=;o)
/Kenneth