NUnit 2.6.2 TestContext.CurrentContext is always null

I'm trying to use TestContext.CurrentContext

2.6.2 for NUnit but it's always null.

I would like to get the result with the test results, but if I run the following code I always get NullReferenceException

in the method TearDown

. All properties within the test and result will throw an exception.

[TestFixture]
public class UtilitiesTests
{
  [TearDown]
  public void TearDown()
  {
    //using console here just for sake of simplicity. 
    Console.WriteLine(String.Format("{0}: {1}", TestContext.CurrentContext.Test.FullName, TestContext.CurrentContext.Result.Status));
  }

  [Test]
  public void CleanFileName()
  {
    var cleanName = Utilities.CleanFileName("my &file%123$99\\|/?\"*:<>.jpg");
    Assert.AreEqual("my-efile12399---.jpg", cleanName);
  }
}

      

How am I wrong?

+1


source to share


1 answer


As per this discussion, you need to make sure you are running the correct version of NUnit testrunner. The version must be NUnit 2.6.2.

Try to run your tests with nunit-console with the correct version.

Update: I installed a new project in VS2012 and added NUnit 2.6.2 and NUnit.Runners 2.6.2 using NuGet. With Resharper Testrunner, I didn't have any error, but also no Console output, so I ran NUnit.exe

from<project-folder>\packages\NUnit.Runners.2.6.2\tools\

This is the result I got:

enter image description here

The result looks fine. I followed your example code above.



However, I had to change the code so that I could run it:

using System;
using NUnit.Framework;

[TestFixture]
public class UtilitiesTests
{
    [TearDown]
    public void TearDown()
    {
        //using console here just for sake of simplicity. 
        Console.WriteLine(String.Format("{0}: {1}", TestContext.CurrentContext.Test.FullName, TestContext.CurrentContext.Result.Status));
    }

    [Test]
    public void CleanFileName()
    {
        var cleanName = "my &file%123$99\\|/?\"*:<>.jpg";
        Assert.AreEqual("my &file%123$99\\|/?\"*:<>.jpg", cleanName);
    }
}

      

You should try running the tests again with NUnit.exe, but before checking that you have the correct validation in Help -> About NUnit ...

Mine looks like this:

enter image description here

+1


source







All Articles