NUnit 3: OneTimeSetUp doesn't fire

﹥>﹥吖頭↗ 提交于 2019-12-07 00:57:28

问题


In NUnit 3, they've replaced the attribute "TestFixtureSetUp" with "OneTimeSetUp". However, it doesn't actually seem to work, unless I'm being a complete idiot.

This is my code below:

[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);
    }
}

The test will start, but it never goes into Init(), and so _diskService is null. Am I doing something wrong here, or could this be a bug?


回答1:


NUnit 3.0 is not supported by Resharper. You should install NUnit adapter and use VS to run your tests. That helped me. More details you can find here https://github.com/nunit/nunit/issues/1089



来源:https://stackoverflow.com/questions/33916416/nunit-3-onetimesetup-doesnt-fire

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!