使用TestCleanUp进行整个项目? [英] Using TestCleanUp for whole Project?

查看:83
本文介绍了使用TestCleanUp进行整个项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我想在我的测试解决方案中每次测试后检查一些状态/日志/ ...。
我发现有[TestCleanup]属性,以便在每个[TestMethod]之后调用该方法。



因为我有很多代码文件,但是想要使用相同的检查每一步,

有没有办法为所有人使用一个全局[TestCleanUp]方法?



在TestCleanUp中我可以访问TestContext最后一个TestMethod。

TestContext.Outcome有不同的统计数据:

通过...测试通过

失败...测试失败

...

错误......我不知道这意味着什么?

此处:http://msdn.microsoft.com/en-us/ library / microsoft.visualstudio.testtools.unittesting.unittestoutcome%28v = vs.90%29.aspx

没有错误描述。

Hi,

I want to check some states/logs/… after each test in my test solution.
I found that there is the [TestCleanup] attribute so that the method is called after each [TestMethod].

As I have many Code files, but want to use the same check on every step,
Is there a way to use one global [TestCleanUp] method for all?

Within the TestCleanUp I can access the TestContext of the last TestMethod.
The TestContext.Outcome has different stats:
Passed … Test is passed
Failed … Test is failed

Error … I don’t know what this means?
Also here: http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.unittestoutcome%28v=vs.90%29.aspx
Is no description for the Error.

推荐答案

Hello Live,

感谢您在MSDN论坛上发帖。

据我所知,我担心你不能对整个项目使用一个全局[TestCleanup]方法。如果在TestCleanup方法中访问TestContext,然后在另一个测试类中调用TestCleanup方法,则会抛出一些异常。
每个测试类使用不同的TestContext。

如果你想做一些操作,比如为整个项目清理资源,我认为你可以使用AssemblyBleanup属性,
标识一个方法,该方法包含在程序集中的所有测试运行后要使用的代码,并释放程序集获取的资源。

有关详细信息,请参阅以下文章:

AssemblyCleanupAttribute类

祝你好运,


这篇关于使用TestCleanUp进行整个项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆