nunit / nunitv2

NUnit 2.x repository. NUnit V2 IS NO LONGER MAINTAINED OR UPDATED. Bugs should be reported in the main NUnit 3.0 repository.
https://github.com/nunit/nunit
Other
25 stars 26 forks source link

TestFixture (Ignore = true) annotation and NullReferenceException #36

Closed fafanoulele closed 9 years ago

fafanoulele commented 9 years ago

I've updated from Nunit 2.6.2 to Nunit 2.6.4. I had a type with this annotation:

[TestFixture (Ignore = true)]
class MyTests
{

}

With this kind of annotation, I had this error:

NUnit-Console version 2.6.4.14350
Copyright (C) 2002-2012 Charlie Poole.
Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov.
Copyright (C) 2000-2002 Philip Craig.
All Rights Reserved.

Runtime Environment - 
   OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
  CLR Version: 2.0.50727.5477 ( Net 3.5 )

ProcessModel: Default    DomainUsage: Single
Execution Runtime: net-3.5

Unhandled Exception:
System.NullReferenceException: Object reference not set to an instance of an object.
   at NUnit.Util.XmlResultWriter.WriteCData(String text)
   at NUnit.Util.XmlResultWriter.WriteReasonElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result)
   at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result)
   at NUnit.Util.XmlResultWriter.SaveTestResult(TestResult result)
   at NUnit.ConsoleRunner.ConsoleUi.CreateXmlOutput(TestResult result)
   at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options)
   at NUnit.ConsoleRunner.Runner.Main(String[] args)

As workaround, now I use this code style in order to ignore a test:

[TestFixture]
[Ignore]
class MyTests
{

}
CharliePoole commented 9 years ago

This usage was never envisioned, since I had not seen it on an attribute before.

However, I suspect that the same thing will happen if you use the named property syntax. The reason is that IgnoreAttribute sets the reason for ignoring the test to the empty string, while directly setting the Ignore property does not do so. XmlResultWriter should be checking for the presence of a non-null message, but does not.

On Tue, Dec 23, 2014 at 11:39 AM, Fabien Bousquet notifications@github.com wrote:

I've updated from Nunit 2.6.2 to Nunit 2.6.4. I had a type with this annotation:

[TestFixture (Ignore = true)]class MyTests {

}

With this kind of annotation, I had this error:

NUnit-Console version 2.6.4.14350 Copyright (C) 2002-2012 Charlie Poole. Copyright (C) 2002-2004 James W. Newkirk, Michael C. Two, Alexei A. Vorontsov. Copyright (C) 2000-2002 Philip Craig. All Rights Reserved.

Runtime Environment - OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1 CLR Version: 2.0.50727.5477 ( Net 3.5 )

ProcessModel: Default DomainUsage: Single Execution Runtime: net-3.5

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object. at NUnit.Util.XmlResultWriter.WriteCData(String text) at NUnit.Util.XmlResultWriter.WriteReasonElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.WriteChildResults(TestResult result) at NUnit.Util.XmlResultWriter.WriteResultElement(TestResult result) at NUnit.Util.XmlResultWriter.SaveTestResult(TestResult result) at NUnit.ConsoleRunner.ConsoleUi.CreateXmlOutput(TestResult result) at NUnit.ConsoleRunner.ConsoleUi.Execute(ConsoleOptions options) at NUnit.ConsoleRunner.Runner.Main(String[] args)

As workaround, now I use this code style in order to ignore a test:

[TestFixture] [Ignore]class MyTests {

}

— Reply to this email directly or view it on GitHub https://github.com/nunit/nunitv2/issues/36.

CharliePoole commented 9 years ago

Since NUnit 2.6.4 is to be our last release of V2, I am creating the label 'v3' to indicate that we should check for the same problem in the 3.0 codebase.

CharliePoole commented 9 years ago

I merged the fix, but am holding this issue open till we check the 3.0 code.

fafanoulele commented 9 years ago

Thank you!

rprouse commented 9 years ago

This does not crash v3, but the test is not ignored. I will enter an issue for that and close this one.