在基类上的ClassCleanup? [英] ClassCleanup on base class?
问题描述
我想为所有单元测试创建一个基类.
I want to create a base class for all my unit tests.
定义ClassCleanup的最佳方法是什么?
what's the best way to define the ClassCleanup ?
析构函数 基类?还是其他?
谢谢
推荐答案
嘿,
创建带有[ClassCleanup()]或[TestCleanUp {}]属性标记的方法,用于在测试运行后将环境返回到已知状态.这可能意味着删除文件夹中的文件或将数据库返回到已知的数据库. 状态.这样的一个示例是在测试订单输入应用程序中使用的方法之后,将库存数据库重置为初始状态. 建议,建议您在[TestCleanup()]或[ClassCleanup()]方法中使用清理代码,然后 不在终结器方法中.从终结器方法引发的异常将不会被捕获,并可能导致意外结果.
Create methods that are marked with either the [ClassCleanup()] or [TestCleanUp{}] attribute are used to return the environment to a known state after a test has run. This might mean the deletion of files in folders or the return of a database to a known state. An example of this is to reset an inventory database to an initial state after testing a method that is used in an order-entry application. It is recommended that you use cleanup code in a [TestCleanup()] or [ClassCleanup()] method and not in a finalizer method. Exceptions that are thrown from a finalizer method will not be caught and can cause unexpected results.
您可能还会发现此博客帖子有趣==> http://blogs.msdn.com/b/ploeh/archive/2007/01/06/classcleanupmayrunlaterthanyouthink.aspx
You might also find this blog post interesting => http://blogs.msdn.com/b/ploeh/archive/2007/01/06/classcleanupmayrunlaterthanyouthink.aspx
HTH
干杯,塔伦(Tarun)
HTH
Cheers, Tarun
这篇关于在基类上的ClassCleanup?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!