开发者

Is there any good way to switch different context between Unit Test and Release. in C#

I have some context in code to be switched depending on whether it is running under test or release. Say in my prod开发者_如何转开发uct coding:

PublishRequest(); // the real one
//PublishRequestPsudo(); // the one want to be run during unit test

The way I am thinking about is make a TestFlag class:

if (!TestFlag.PublishFlag)
{
    PublishRequest();
}
else
{
    PublishRequestPsudo();
}

This seems verbose if I have many place to do that. Is there any good pattern to do it?


A pretty good way to acheive the same is Dependency Injection/Inversion Of Control

Another good resource on this is Caching ArchitectureTestability, Dependency Injection and Multiple Providers

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜