我可以有之前和测试由NUnit的运行之后执行代码? [英] Can I have code that executes before and after tests are run by NUnit?

查看:162
本文介绍了我可以有之前和测试由NUnit的运行之后执行代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一大堆的NUnit的测试,这在文件系统中创建垃圾数据(坏的,我知道,但我有过这个小控件)。目前我们有一个清理工具,删除这些临时等,但我希望能够自动运行清理工具。我必须能够运行它后所有测试完成运行。我也有类似的检查,我想在开始做,以确保有没有这些临时从以前可能改变测试结果的运行留下了。

I've got a bunch of tests in NUnit which create garbage data on the filesystem (bad, I know, but I have little control over this). Currently we have a cleanup tool that removes these temporaries and such, but I'd like to be able to run that cleanup tool automatically. I'd have to be able to run it after all tests have finished running. I have similar checking that I'd like to do at the beginning, to ensure that there are none of these temporaries left from previous runs that might change the outcome of the tests.

是这样的事情简单还是我将不得不实施这样的事情了一个全新的测试运行?

Is such a thing simple or am I going to have to implement a whole new test runner for such a thing?

推荐答案

是的,

使用的 [SetUpFixture] 属性上一类和 [设置] [TearDown中] 属性与该类方法。

Use the [SetUpFixture] attribute on a class and the [SetUp] and [TearDown] attributes on methods with that class.

在SetUpFixture的设置方法与之前的任何包含在其命名空间中的灯具执行一次。毕竟灯具已完成执行执行一次拆机方法。在下面的实施例中,该方法RunBeforeAnyTests()在NUnit.Tests命名空间的任何测试或设置方法之前被调用。该方法RunAfterAnyTests()被命名空间中的所有的测试,以及他们的个人或夹具拆解完成exection之后调用

The SetUp method in a SetUpFixture is executed once before any of the fixtures contained in its namespace. The TearDown method is executed once after all the fixtures have completed execution. In the examples below, the method RunBeforeAnyTests() is called before any tests or setup methods in the NUnit.Tests namespace. The method RunAfterAnyTests() is called after all the tests in the namespace as well as their individual or fixture teardowns have completed exection.

< A HREF =htt​​p://www.nunit.org/index.php?p=setupFixture&r=2.5.5>来源(它说2.4的页面上,但它在2.5可用)

Source (it says 2.4 on the page, but it is available in 2.5)

这篇关于我可以有之前和测试由NUnit的运行之后执行代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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