0

I'm getting an internal NullReferenceException from NUnit 2.6.4 while running a unit test fixture:

SetUp : System.NullReferenceException : Object reference not set to an instance of an object
  at NUnit.Core.NUnitFramework.GetResultState (System.Exception ex) <0x40e3da10 + 0x00068> in <filename unknown>:0 
  at NUnit.Core.TestMethod.RecordException (System.Exception exception, NUnit.Core.TestResult testResult, FailureSite failureSite) <0x40e3d920 + 0x00093> in <filename unknown>:0 
  at NUnit.Core.TestMethod.RunTestCase (NUnit.Core.TestResult testResult) <0x40e34a30 + 0x00168> in <filename unknown>:0 
  at NUnit.Core.TestMethod.RunTest () <0x40e30060 + 0x0013f> in <filename unknown>:0

I've tried with both JetBeans Rider and MonoDevelop. I believe it has something to do with my implementation of IEquatable because the issue goes away when I remove the implementation. My implementation involves a class deriving an abstract class that implements IEquatable<Derived>, with the following functions defined/overwritten (as well as == and != operators):

    public override bool Equals(object o){
        var a = o as Derived;
        return a != null && Equals(a);
    }

    public new static bool Equals(object a, object b){
        if(a == null || b == null) return false;
        if(a.GetType() != typeof(Derived) || b.GetType() != typeof(Derived))
            return false;
        return ((Derived) a).Equals((Derived) b);
    }

    public bool Equals(Derived a){
        return a != null && a.Id == Id;
    }

    public override int GetHashCode(){
        // ReSharper disable once NonReadonlyMemberInGetHashCode
        return _id.GetHashCode();
    }

Is this an NUnit bug or is there something wrong with my implementation?

Michael
  • 59
  • 6
  • How did you define == and != operators? – Sergey Berezovskiy Apr 27 '17 at 22:51
  • == just compares a few public fields in the object, and != is defined as the inverse of == – Michael Apr 27 '17 at 22:54
  • Could be a bug, as NUnit v2 is not maintained. Here are some recent fixes in NUnit 3.x, which could be present in v2 as well: https://github.com/nunit/nunit/issues?q=is%3Aissue+iequatable+is%3Aclosed – Charlie Apr 28 '17 at 01:29
  • That was my first thought. I'd like to try to run it against 3.6.1 but everytime I do I get an `UnsupportedFrameworkException` – Michael Apr 28 '17 at 15:13

0 Answers0