在 NUnit 3 中,他们将属性“TestFixtureSetUp”替换为“OneTimeSetUp”。但是,它实际上似乎不起作用,除非我是一个完全的白痴。
这是我下面的代码:
[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 为空。我在这里做错了什么,或者这可能是一个错误?