gpt4 book ai didi

.net - NUnit 3 : OneTimeSetUp doesn't fire

转载 作者:行者123 更新时间:2023-12-02 11:17:19 26 4
gpt4 key购买 nike

在 NUnit 3 中,他们用“OneTimeSetUp”替换了属性“TestFixtureSetUp”。然而,它实际上似乎不起作用,除非我是一个十足的白痴。

这是我的代码:

[TestFixture]
public class DiskServiceTests
{
private readonly Mock<IDriveInfoWrapper> _driveInfoWrapper = new Mock<IDriveInfoWrapper>();
private IDiskService _diskService;

[OneTimeSetUp]
public void Init()
{
_diskService = new DiskService(_driveInfoWrapper.Object);
}

[Test]
public void GetDriveInfo_ShouldReturnDriveInfo()
{
// Act
var result = _diskService.GetDriveInfo();

// Assert
Assert.IsNotNull(result);
}
}

测试将开始,但它永远不会进入 Init(),因此 _diskService 为 null。我在这里做错了什么吗,或者这可能是一个错误?

最佳答案

Resharper 不支持 NUnit 3.0。您应该安装 NUnit 适配器并使用 VS 来运行测试。这对我有帮助。您可以在这里找到更多详细信息 https://github.com/nunit/nunit/issues/1089

关于.net - NUnit 3 : OneTimeSetUp doesn't fire,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33916416/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com