自动化测试项目中的实用程序类 - 静态、单例还是其他设计?
我在堆栈溢出上搜索了很多关于这个问题的信息,并认为这个问题足够不同,值得提出一个新问题。
对于集成测试,我需要启用分布式事务协调器服务 (SQL Server),以便可以使用 MSTestExtensions 的数据库回滚功能。
所以我需要如下方法:
public void StartService(string serviceName)
public void StopService(string serviceName)
public void RestartService(string serviceName)
制作一个静态类会很容易。使此类成为c# 中的单例的工作也不难。
那么这里使用单例还是静态类真的很重要吗?这对我来说似乎微不足道,但也许有一个更适合这种类型的事情?
我认为我不需要使用接口、多态性、可扩展性或传递包含这些方法的类的能力。所以单例的这些好处在这种情况下并没有真正的帮助。最后,我能看到的唯一优点是类的延迟加载,而不必向每个方法添加静态。
I've searched quite a bit about this on stack overflow and think this question is different enough to merit a new question.
For integration tests, I need to enable the Distributed Transaction Coordinator service (SQL Server) so that I can use the database rollback feature of MSTestExtensions.
So I need methods like as follows:
public void StartService(string serviceName)
public void StopService(string serviceName)
public void RestartService(string serviceName)
It would be very easy to make a static class. The work to make this class a singleton in c# is not hard either.
So does it really matter if one uses a singleton or a static class here? It seems trivial to me, but perhaps one is more appropriate for this type of thing?
I don't think I need to use interfaces, polymorphism, extensibility, or the ability to pass this class that contains these methods around. So such benefits of Singletons are not really helpful in this case. In the end the only advantages I can see is lazy loading of the class and not having to add static to every method.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您的数据相对较少并且不需要 OOP 功能,则静态类可以很好地工作。我怀疑在这种情况下,它会运作良好。
Static classes work well if you have relatively little data and don't need the OOP features. I suspect that in this case, it would work well.