- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
TextFixture 和测试
public class TestFixture : IDisposable
{
public TestFixture()
{
var options = new ChromeOptions();
options.AddExcludedArgument("enable-automation");
options.AddAdditionalCapability("useAutomationExtension", true);
WebDriver.Init("https://localhost:44335/", Browser.Chrome, options);
WebDriver.GetDriver.Manage().Window.Maximize();
}
public void Dispose()
{
WebDriver.Close();
}
}
public abstract class Test : IClassFixture<TestFixture>
{
}
AuthTest
public abstract class AuthTest : Test
{
[Fact, Priority(-1)]
public void LoginTest()
{
var home = GetPage<HomePage>();
home.LoginModal.Open();
home.LoginModal.EnterLoginText(new Login("user", "pw"));
home.LoginModal.Login();
GetPage<DashboardPage>().IsAt();
}
}
家庭测试
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
public sealed class HomeTest : AuthTest
{
}
个人资料测试
[TestCaseOrderer(PriorityOrderer.Name, PriorityOrderer.Assembly)]
public sealed class ProfileTest : AuthTest
{
[Fact, Priority(0)]
public void OpenProfilePageTest()
{
var profile = GetPage<ProfilePage>();
profile.GoTo();
profile.IsAt();
}
[Fact, Priority(1)]
public void LogoutTest() => GetPage<DashboardPage>().Logout();
}
几天前我写了这段代码,它用来创建 1 个浏览器实例。我今天又开始了这个项目,现在突然夹具被执行了两次,它打开了两个单独的浏览器(这导致我的测试失败)。我认为 IClassFixture
应该像 NUnit 中的 [OneTimeSetUp]
属性一样只执行一次。为什么我的夹具执行了两次?
当我运行所有测试(所有测试运行ProfileTest
和HomeTest
)时会发生这种情况。例如,如果我单独运行两个测试之一,那么只会打开 1 个浏览器实例并且测试通过。
我正在使用 XUnit 2.4.0。
- 编辑-
当我使用时:
VS 2019(运行所有测试):它同时打开 2 个浏览器并失败。
VS 2019(调试所有测试):它同时打开2个浏览器并失败。
Jetbrain 的 Rider IDE(运行所有测试):它同时打开 2 个浏览器并失败。
Jetbrain 的 Rider IDE(调试所有测试):它打开 1 个浏览器直到 HomeTest
完成,然后打开另一个浏览器用于 ProfileTest
,两个测试都通过(包括 LoginTest
)。
最后一个是它应该如何工作的,当我以前使用 NUnit 时它曾经是这样的。
最佳答案
来自 https://xunit.net/docs/shared-context#class-fixture
You can use the class fixture feature of xUnit.net to share a single object instance among all tests in a test class
注意在一个测试类
在您的情况下,您有两个单独的类 HomeTest
和 ProfileTest
,无论它们都派生自同一个抽象类,xUnit 将它们视为两个不同的测试类。
考虑改用Collection Fixtures
。
https://xunit.net/docs/shared-context#collection-fixture
You can use the collection fixture feature of xUnit.net to share a single object instance among tests in several test class
关于c# - XUnit 类夹具 (IClassFixture) 正在执行两次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58505734/
我有以下简化的伪代码 class CommonSetup { public void CommonSetup() { // do stuff once per cla
我的问题是如何在一个测试类中设置多个夹具? 但是 Zoo 类的构造函数不能处理多个 fixture。 例如: public class Zoo : IClassFixture, IClassFixtu
TextFixture 和测试 public class TestFixture : IDisposable { public TestFixture() { var
我正在使用 xUnit 进行集成测试。为此,我使用了一个 localdb 实例。话虽如此,我想用一些预定义的数据启动一次数据库实例,当然我希望所有测试用例都如此。我可以编写隔离的每个测试用例,这样它们
我一直使用 Nunit,现在转向 XUnit。 当我没有实现 IClassFixture 时,我成功地使用了 ITestOutputHelper,例如: public myClassTest(ITes
我为集成测试升级到 .net core 3.0 时遇到的问题做了一个 repo : https://github.com/ranouf/TestingWithDotNetCore3_0 当我启动测试时
我为集成测试升级到 .net core 3.0 时遇到的问题做了一个 repo : https://github.com/ranouf/TestingWithDotNetCore3_0 当我启动测试时
我是一名优秀的程序员,十分优秀!