Spurious assertion failure

35 views
Skip to first unread message

finitish

unread,
Nov 29, 2013, 11:30:09 PM11/29/13
to nuni...@googlegroups.com
The Assert in the C# code at the bottom of this post fails, with the following stack trace:
> .\Finity.Tests\bin\Debug\Finity.Tests.exe

Unhandled Exception: System.NullReferenceException: Object reference not set to an instance of an object.
   at NUnit.Framework.Assert.That(Object actual, IResolveConstraint expression, String message, Object[] args)
   at NUnit.Framework.Assert.That(Boolean condition)
   at Finity.Tests.Program.Main(String[] args) in \\store\pers\vers\finity\Finity.Tests\Program.cs:line 16

#

Uncommenting the 3 commented lines executes a do-nothing test, and the Assert no longer fails:
> .\Finity.Tests\bin\Debug\Finity.Tests.exe
NUnitLite 1.0.0 (.NET 4.5)
Copyright 2013, Charlie Poole

Runtime Environment -
    OS Version: Microsoft Windows NT 6.1.7601 Service Pack 1
  .NET Version: 4.0.30319.18052

Tests run: 1, Passed: 1, Errors: 0, Failures: 0, Inconclusive: 0
  Not run: 0, Invalid: 0, Ignored: 0, Skipped: 0
Elapsed time: 00:00:00.0080000

#

NUnit does not have this problem.

Weird? My environment is 64-bit Windows 7, and nunitlite is added as NuGet package to a default console application project in a default Visual Studio 2012 solution.

#

namespace Finity.Tests
{
  using System;
 
  using NUnit.Framework;
 
  class Program
  {
    //[Test]
    //public void Null() { }
 
    static void Main(string[] args)
    {
      //new NUnitLite.Runner.TextUI().Execute(args);
 
      Assert.That(1 == 1);
    }
  }
}

###


Charlie Poole

unread,
Nov 30, 2013, 4:11:44 PM11/30/13
to nuni...@googlegroups.com
So you have an assertion outside of any test method and which is not
run under NUnitLite at all. It throws an exception because it's not
running in the proper environment. We could analyze in detail exactly
how it fails, but that does not seem very useful. Just don't try to
Assert outside of your tests!

In the case of NUnit, a Main with an Assert would not cause a problem,
because it would not be executed at all.

Charlie
> --
> You received this message because you are subscribed to the Google Groups
> "NUnitLite" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to nunitlite+...@googlegroups.com.
> To post to this group, send email to nuni...@googlegroups.com.
> Visit this group at http://groups.google.com/group/nunitlite.
> For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages