是否可以在运行所有测试之前执行代码?

发布于 2024-08-18 10:48:17 字数 153 浏览 9 评论 0原文

我正在编写集成测试。现在,在运行测试之前,我想使用初始数据设置数据库。为此,我创建了一个单独的项目,该项目在执行测试项目之前运行(使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

空心空情空意 2024-08-25 10:48:17

您可以使用 [AssemblyFixture] 属性声明一个类;以及使用 [FixtureSetUp][FixtureTearDown] 属性来定义程序集级设置和拆卸方法。

[AssemblyFixture]
public class MyAssemblyFixture
{
   [FixtureSetUp]
   public void SetUp()
   {
      // Code to be run before any test fixture within the assembly are executed.
   }

   [FixtureTearDown]
   public void TearDown()
   {
      // Code to be run after all test fixture within the assembly are executed.
   }
}

事实上,语法类似于通常在测试装置级别使用众所周知的 [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.

[AssemblyFixture]
public class MyAssemblyFixture
{
   [FixtureSetUp]
   public void SetUp()
   {
      // Code to be run before any test fixture within the assembly are executed.
   }

   [FixtureTearDown]
   public void TearDown()
   {
      // Code to be run after all test fixture within the assembly are executed.
   }
}

In fact, the syntax is similar to what is usually done at test fixture level with the well-known [TestFixture], [SetUp], and [TearDown] attributes.

给我一枪 2024-08-25 10:48:17

通常,测试框架具有方法属性,允许在每次测试之前、每次测试之后、测试运行之前和测试运行之后执行代码。我不知道 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

野味少女 2024-08-25 10:48:17

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文