NUnit:如何仅使用一个 userRole 开始测试,而 TestFixture 中定义了 3 个不同的 userRole

NUnit: How to start a test only with one userRole, while there are 3 different userRoles defined in TestFixture

我有一个“回归测试”Class,其中我在 TestFixture 中定义了 3 个不同的用户角色

在回归测试中,我正在测试除主要特性功能之外的其他网络应用程序功能。目前我有 5 个不同的测试,如下面的屏幕截图所示。

我现在想要的是,前 4 个测试方法将仅使用 admin 用户角色启动,最后一个名为 UserRights 的测试方法应该仅使用 [=12] 进行测试=] 和 hsuIntRequest

我现在遇到的问题是,所有 5 种测试方法都将使用在 TestFixtureclass 中定义的所有 userRoles 启动

有没有办法告诉 TestMethod 应该使用哪个 UserRole 开始测试?

在 NUnit 中,TestFixture 的主要目的是将所有需要通用设置的测试组合在一起。因此,如果前四个测试需要用户角色 admin,而最后一个测试需要两个不同角色下的 运行,则它们不属于同一个 TestFixture。

您可以将测试重组为两个固定装置,类似于:

[TestFixture("adminInt")]
public class FirstFixture
{
    // Your first four tests here
}

[TestFixture("hsuINT")]
[TestFixture("hsuIntRequest")]
public class SecondFixture
{
    // Your last test here
}

当然,第一个 fixture 并不真的需要参数...如果您愿意,可以对角色进行硬编码。

如果拆分夹具需要复制大量设置代码(您没有在问题中显示),您可以从具有设置的公共基础派生每个 class。在那种情况下,所有三个 classes 都应该有参数,但只有两个派生的 classes 应该有 TestFixture 属性。