nunit3-vs-adapter: An exception occurred while test discoverer 'NUnit3TestDiscoverer' was loading tests. Exception: Object reference not set to an instance of an object, with VS2015
- NUnit =3.12 and NUnit3TestAdapter =3.17
- Visual Studio preofessional version 15.3.3
- .net version 4.6.1
- not installed vsix
Steps to Repro
- Create a unit test project
- Remove mstest in nuget and install nunit and nunittestadapter latest version
- Create a test with OneTimeSetUp attribute
using NUnit.Framework;
using System;
namespace nUnittest
{
[TestFixture]
public class UnitTest1
{
[OneTimeSetUp]
public static void OneTimeSetUp()
{
Console.WriteLine("OneTimeSetUp");
}
[SetUp]
public void SetUp()
{
Console.WriteLine("SetUp");
}
[TearDown]
public void TearDown()
{
Console.WriteLine("TearDown");
}
[Test]
public void Test()
{
Console.WriteLine("Test");
}
[OneTimeTearDown]
public static void OneTimeTearDown()
{
Console.WriteLine("OneTimeTearDown");
}
}
}
Firs time passes,rebuild the solution>>Observe console >>error will display as mentioned in title ,test will pass,[OneTimeSetUp] / [SetUp] will not be executed packages.config
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.12.0" targetFramework="net461" />
<package id="NUnit3TestAdapter" version="3.17.0" targetFramework="net461" />
</packages>
Close VS>>Run IFix vstestcache -f >>Rebuild>> works,first time,Test runs, later exception is thrown,One time setup not runs.
An exception occurred while test discoverer 'NUnit3TestDiscoverer' was loading tests. Exception: Object reference not set to an instance of an object
I tried all the workaround mentioned in https://github.com/nunit/nunit3-vs-adapter/issues/261 I tried removing the cache,works for first time,later again the same problem,cant restart everytime I changed test process acritecture to 64 still same
Note On running through nunit3-console all methods works
>nunit3-console D:\automationRepo\nUnitTest\nUnittest\bin\Debug\nUnittest.dll
NUnit Console Runner 3.11.1 (.NET 2.0)
Copyright (c) 2020 Charlie Poole, Rob Prouse
04 September 2020 18:28:56
Runtime Environment
OS Version: Microsoft Windows NT 6.2.9200.0
Runtime: .NET Framework CLR v4.0.30319.42000
Test Files
D:\automationRepo\nUnitTest\nUnittest\bin\Debug\nUnittest.dll
SetUp
Test
TearDown
OneTimeSetUp
OneTimeTearDown
Run Settings
DisposeRunners: True
WorkDirectory: D:\automationRepo\nUnitTest\nUnittest\bin\Debug
ImageRuntimeVersion: 4.0.30319
ImageTargetFrameworkName: .NETFramework,Version=v4.6.1
ImageRequiresX86: False
ImageRequiresDefaultAppDomainAssemblyResolver: False
RuntimeFramework: net-4.0
NumberOfTestWorkers: 4
Test Run Summary
Overall result: Passed
Test Count: 1, Passed: 1, Failed: 0, Warnings: 0, Inconclusive: 0, Skipped: 0
Start time: 2020-09-04 12:58:56Z
End time: 2020-09-04 12:58:57Z
Duration: 0.909 seconds
Results (nunit3) saved as TestResult.xml
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 2
- Comments: 28 (12 by maintainers)
Commits related to this issue
- Fix for nullref #781 — committed to nunit/nunit3-vs-adapter by OsirisTerje 4 years ago
I can confirm this issue. I am on VS2015 too and experience the same behaviour (i.e. tests are only discovered once after startup of VS; after any further build operation the discovered tests are gone with the exception of the NUnit3TestDiscoverer. VERY annoying!).
I could solve this issue by removing the ‘Nunit 3 Test Adapter’ from Tools > Extensions and Updates, restarting VS and downgrading the NuGet package ‘NUnit3TestAdapter’ from v3.17.0 to v3.16.1. Hope that helps!