【问题标题】:xunit 2.0 - run code before and after all testsxunit 2.0 - 在所有测试之前和之后运行代码
【发布时间】:2015-05-30 08:50:48
【问题描述】:

现在当 Xunit 2.0 发布时,在运行所有测试之前和之后运行设置/拆卸代码的可能性是什么? 这在 Xunit 1 中是不可能的,但根据xUnit.net - run code once before and after ALL tests,有计划在 2.0 中支持这种行为。

【问题讨论】:

标签: xunit


【解决方案1】:

在您的情况下,Collection Fixtures 可能会有所帮助。您可以在 xUnit 文档中找到 example。在此示例中,DatabaseFixture 类的构造函数和 Dispose 方法是您可以编写设置/拆卸代码的地方。为您的测试创建一个基类,并为它使用这个集合夹具。

【讨论】:

    【解决方案2】:

    这是 xUnit 发布的 AssemblyFixture 示例,它展示了如何获得程序集级别的设置和清理:https://github.com/xunit/samples.xunit/tree/master/AssemblyFixtureExample

    【讨论】:

      猜你喜欢
      • 2013-01-24
      • 1970-01-01
      • 1970-01-01
      • 2019-07-19
      • 2014-05-02
      • 2020-10-24
      • 2021-07-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多