- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我们使用 MSTest 时,我们有几个环境有自己的运行设置。由于 Microsoft 正在放弃 MSTest,我们将转向 xUnit。无论是通过运行设置还是命令行属性,我都需要一种在 xUnit 测试中指定 TestRunParameters 的方法。 xUnit 是否有像 MSTest 这样的本地方式来做到这一点,还是我需要提出自己的解决方案?
最佳答案
虽然在使用 xUnit 时您仍然可以使用 RunSettings 来控制 vstest.console 的某些方面,但当前版本没有本地方式来传递参数。我相信 v3 会有某种参数传递。
现在您可以使用环境变量,但如果您在同一系统上并行运行多个测试集,则会发生冲突。
我使用一个基类,它读入带有该测试集设置的 TestSettings.json 文件。使用以下代码,我可以传入新类型并让基类 json 读取器读取它们。
/// <inheritdoc />
/// <summary>
/// Common TestBase which uses CommonSettingsModel. Use TestBase<T> to override with custom settings Type.
/// </summary>
public abstract class TestBase : TestBase<CommonSettingsModel>
{
}
/// <inheritdoc />
/// <summary>
/// Common TestBase for loading settings.
/// </summary>
/// <typeparam name="T">Type to read TestSettings.json file</typeparam>
public abstract class TestBase<T> where T : ICommonSettings, new()
{
/// <inheritdoc />
/// <summary>
/// Constructor loads Settings T
/// </summary>
protected TestBase()
{
Settings = SettingsUtil.GetSettings<T>();
}
/// <summary>
/// Settings T loaded from TestSettings.json
/// </summary>
protected T Settings { get; }
}
您也可以使用 Class 或 AssemblyFixture 进行相同类型的测试。
public class DatabaseFixture : IDisposable
{
public DatabaseFixture()
{
Db = new SqlConnection("MyConnectionString");
// ... initialize data in the test database ...
}
public void Dispose()
{
// ... clean up test data from the database ...
}
public SqlConnection Db { get; private set; }
}
public class MyDatabaseTests : IClassFixture<DatabaseFixture>
{
DatabaseFixture fixture;
public MyDatabaseTests(DatabaseFixture fixture)
{
this.fixture = fixture;
}
// ... write tests, using fixture.Db to get access to the SQL Server ...
}
关于xunit - 什么是 xUnit 运行设置等价物?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38458979/
我找不到任何关于我认为是一个相当明显的问题的信息。xunit.console.clr4 命令行 arg 帮助状态: usage: xunit.console.clr4 [options] usage
当我们使用 MSTest 时,我们有几个环境有自己的运行设置。由于 Microsoft 正在放弃 MSTest,我们将转向 xUnit。无论是通过运行设置还是命令行属性,我都需要一种在 xUnit 测
我试图使用 OpenCover(今天下载)来覆盖我的测试。这是我使用的命令行: OpenCover.Console.exe -target:"c:\Programmes2\xunit\xunit.co
我正在学习使用单元测试,我创建了一个项目,添加了 xunit 引用。 以及以下代码: namespace UnitTestProject { public partial class Form
Closed. This question does not meet Stack Overflow guidelines。它当前不接受答案。 想要改善这个问题吗?更新问题,以便将其作为on-topi
我有一个在 Windows 上构建的程序集 我想在 Linux 中的单声道上运行 xUnit 测试。 但是,我发现虽然其中 400 个测试可以(按顺序)运行,但某些测试要么挂起 xUnit 运行程序,
我有一个 F# 类库,其中包含使用 NuGet 安装的“xUnit.net”和“xUnit.net Runners”包。我有以下代码: module XUnitTest open Xunit [] l
I know that this question has been asked multiple times before I raise it again, However I still cou
我们使用的是 dotCover 2.7 和 xUnit.net 1.9.2。 在我的机器 (Windows 7) 和同事的机器 (Windows 8) 上,我们可以从命令行针对我们使用 xUnit.n
是否可以将 xUnit 与 LINQPad 一起使用? 能够首先为在 LINQPad 中设计的概念编写一些测试会很棒。这比添加另一个 ConsoleApp23423894238 更容易,只是为了能够快
我有一组需要共享状态的 xunit.net 测试。希望我希望这些测试能够并行运行。所以我希望运行者这样做: 创建共享夹具 运行并行所有使用该夹具的测试 在阅读 xunit 文档时,它说要在测试类之间共
我需要跳过基于类中某些 bool 条件的测试方法。是否可以?如何实现?我试过扩展 FactAttribute 但我无法获得 Test 类的实例。 我的代码如下: using System; using
我有兴趣在多个类上重用测试理论,特别是一些需要相同测试的构造函数。我最初有使用委托(delegate)来执行此功能的想法。 但是,我认为我可能正在尝试重新发明轮子,尽管 C# 具有一些功能,但我认为我
我正在为我的 DataAccessRepository(使用 Entity Framework )类编写测试用例。此类在构造函数中采用两个参数。 1)连接对象 2) Automapper 对象 现在,
xUnit 相当于 NUnit 的 [TestFixtureSetUp] ? 我们探索发现IUseFixture相当于[TestFixtureSetUp] ,但它没有按预期工作。 正如我们所探索的(在
Xunit 1.9.x 为用户提供了 DynamicSkipExample.cs 帮助他设置动态跳过 [Fact] 的示例。 事实证明,这在执行一些跨平台开发时非常有用。当由于底层上下文(操作系统、文
我正在尝试使用 xUnit.net 作为 SpecFlow 的测试运行器。来自官方下载区的 SpecFlow 1.2 二进制文件不包含 xUnit.net 提供程序,但 GitHub 上的主分支有一个
当我尝试运行我的 xUnit.net 测试时,出现此错误: [xUnit.net 00:00:00.63] xunit.UnitTest1.TestTheAnswer [FAIL] Fai
我已经转移到 xunit.net 2.0 测试版,但需要 AutoFixture 的一些功能,这仍然取决于当前的 1.9.2 稳定版本 (CompositeDataAttribute)。据我所知 Au
我已经使用 NUnit 多年了,我想尝试 XUnit。所以我安装了 XUnit 并运行了允许您通过 TD.net 运行 XUnit 的可执行文件。 我似乎不能一次运行多个测试。使用 NUnit + T
我是一名优秀的程序员,十分优秀!