8

在 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 为空。我在这里做错了什么,或者这可能是一个错误?

4

1 回答 1

7

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

于 2015-11-29T20:06:52.357 回答