Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NUnit 3: OneTimeSetUp doesn't fire

Tags:

.net

nunit-3.0

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?

like image 300
Tom Avatar asked Nov 25 '15 12:11

Tom


1 Answers

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

like image 194
Olga Avatar answered Oct 03 '22 23:10

Olga