是否可以在运行所有测试之前执行代码?
我正在编写集成测试。现在,在运行测试之前,我想使用初始数据设置数据库。为此,我创建了一个单独的项目,该项目在执行测试项目之前运行(使用 MSBuild 文件)。但是,我想要将数据库设置代码合并到 testproject 中,并在执行任何测试之前执行它。我正在使用 MBunit 3。这可能吗?
I am writing integration tests.Now, before tests are run I want to setup the database with initial data.For this, I have created a separate project, which is run before test project is executed(using MSBuild file).But, I want to merge the db setup code in testproject, and have it executed before any tests get executed.I am using MBunit 3.Is it possible?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 [AssemblyFixture] 属性声明一个类;以及使用 [FixtureSetUp] 和 [FixtureTearDown] 属性来定义程序集级设置和拆卸方法。
事实上,语法类似于通常在测试装置级别使用众所周知的 [TestFixture]、[设置] 和 [TearDown] 属性。
You can declare a class with the [AssemblyFixture] attribute; and a few methods into that class with the [FixtureSetUp] and [FixtureTearDown] attributes to define assembly-level setup and teardown methods.
In fact, the syntax is similar to what is usually done at test fixture level with the well-known [TestFixture], [SetUp], and [TearDown] attributes.
通常,测试框架具有方法属性,允许在每次测试之前、每次测试之后、测试运行之前和测试运行之后执行代码。我不知道 mbunit 的属性,因为我没有使用过它。
查看此链接...我确信 mbunit 具有与 nunit 类似的属性
http://blogs.msdn.com/nnaderi/archive/2007/02/01/mstest-vs-nunit-frameworks.aspx
Generally test frameworks have method attributes to allow code to be executed before each test and after each test and before a test run and after a test run. I don't know the attributes for mbunit as I haven't used it.
Check out this link... I am sure mbunit would have attributes that are similar to nunit
http://blogs.msdn.com/nnaderi/archive/2007/02/01/mstest-vs-nunit-frameworks.aspx
MBunit 没有过多的文档,但是快速谷歌搜索可以找到这篇文章,其中我可以看出 MBUnit 具有与 NUnit [SetUp] 和 [TearDown] 类似的属性。用这些装饰的方法分别在每次测试之前和之后执行。
MBunit doesn't have excessive documentation, but quick googling gives this article from which I can tell that MBUnit has similar attributes to NUnit [SetUp] and [TearDown]. Methods decorated with those are executed before, and after each test respectively.