nunit-console icon indicating copy to clipboard operation
nunit-console copied to clipboard

System.ArgumentNullException with SetUpFixture in no namespace, and NUnit Framework 3.6.1

Open pavel-spacil opened this issue 5 years ago • 8 comments

NuGet Packages used:

  • NUnit 3.6.1
  • NUnit.Console 3.11.1

Command line arguments: ...bunch of dll files.... --trace=Error --labels=On --timeout=30000 --noheader --framework=net-4.5 --result=C:\path\to\NUnitResults.xml;format=nunit2 --skipnontestassemblies --agents=4 --x86 --teamcity

After upgrade of NUnit.Console from 3.10.0 to 3.11.1 every console run ends with:

System.ArgumentNullException : Value cannot be null.
Parameter name: s
--ArgumentNullException
Value cannot be null.
Parameter name: s
   at System.IO.StringReader..ctor(String s)
   at System.Xml.XmlDocument.LoadXml(String xml)
   at NUnit.Engine.TestEngineResult.get_XmlNodes()
   at NUnit.Engine.Internal.ResultHelper.Merge(IList`1 results)
   at NUnit.Engine.Runners.AggregatingTestRunner.RunTests(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.AbstractTestRunner.Run(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.RunTests(ITestEventListener listener, TestFilter filter)
   at NUnit.Engine.Runners.MasterTestRunner.Run(ITestEventListener listener, TestFilter filter)
   at NUnit.ConsoleRunner.ConsoleRunner.RunTests(TestPackage package, TestFilter filter)
   at NUnit.ConsoleRunner.ConsoleRunner.Execute()
   at NUnit.ConsoleRunner.Program.Main(String[] args)

Do you have any clues what's wrong here? Tests are properly reported on CI server (TeamCity) but NUnit console ends with this exception and exit code -100.

Thanks

pavel-spacil avatar Feb 20 '20 14:02 pavel-spacil

Hi,

Please can you run with trace=debug and add the log files? Thanks.

ChrisMaddock avatar Feb 20 '20 19:02 ChrisMaddock

After deeper investigation I've found out that the issue was caused by presence of class file with class without namespace. It looked like:

using System;
using NUnit.Framework;

[SetUpFixture]
public class FixtureSetup
{
	[OneTimeSetUp]
	public void RunBeforeAnyTests()
	{
		Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
	}
}

After change to

using System;
using NUnit.Framework;

namespace Corrent.Namespace.For.Tests 
{
	[SetUpFixture]
	public class FixtureSetup
	{
		[OneTimeSetUp]
		public void RunBeforeAnyTests()
		{
			Environment.CurrentDirectory = TestContext.CurrentContext.TestDirectory;
		}
	}
}

it runs fine now.

pavel-spacil avatar Feb 21 '20 08:02 pavel-spacil

Thanks Pavel - this should work, so looks like you’ve found a bug. Are the results different if you upgrade the Nunit framework version?

@nunit/engine-team I’m away in holiday at the moment - if anyone’s got a chance to take a quick look at this, that’d be great. Sounds like it can’t be too complicated. If not - I’ll take a look when I’m back. 😊

ChrisMaddock avatar Feb 22 '20 19:02 ChrisMaddock

I took a very quite look (too much real work at the moment). And the problem does not exists when using NUnit 3.8, so something has changed between 3.7.1 - still failing on this release - and 3.8. Looking at the release notes - https://github.com/nunit/nunit/releases/tag/3.8 - I cannot see an issue that exactly matches this, but my guess would be that https://github.com/nunit/nunit/issues/2361 also solved this issue. Currently, I don't have time to look at this in much more detail, but can you see if 3.8 (or better the hotfix 3.8.1) also works in your environment.

mikkelbu avatar Feb 23 '20 19:02 mikkelbu

Hi, it will give it a try, for some reasons we still use NUnit 3.6.1 so I will upgrade that and rerun.

Thanks

pavel-spacil avatar Feb 24 '20 11:02 pavel-spacil

Thanks Mikkel, really appreciate that! @pavel-spacil - How did it go? 🙂

Providing upgrading the framework resolves this issue, we should patch this up for the next release of the console, but upgrading the framework seems like a suitable workaround for this version. Pavel - would you have any interest in supplying a PR to fix this issue? We'd love the help! 😁

ChrisMaddock avatar Mar 01 '20 14:03 ChrisMaddock

I've tried to run same code while using latest NUnit 3.12.0 and issue is gone.

@ChrisMaddock I may give it a try but NUnit sources always were a little bit mystery for me :)

pavel-spacil avatar Mar 02 '20 11:03 pavel-spacil

Great! Glad we have a workaround.

If you do end up having a dig - let us know if we can help at all. 🙂

ChrisMaddock avatar Mar 02 '20 21:03 ChrisMaddock