NUnit 3:OneTimeSetUp不会触发 [英] NUnit 3: OneTimeSetUp doesn't fire

查看:44
本文介绍了NUnit 3:OneTimeSetUp不会触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在NUnit 3中,他们已将"TestFixtureSetUp"属性替换为"OneTimeSetUp".但是,除非我是一个完全的白痴,否则它实际上似乎并不起作用.

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.

这是我的下面的代码:

[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.我在这里做错什么了吗,或者这可能是个错误?

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?

推荐答案

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

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

这篇关于NUnit 3:OneTimeSetUp不会触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆