Cybercop
Cybercop

Reputation: 8674

Test method is inconclusive: Test wasn't run. Error?

I have a test class and below I have posted a sample test from the test class

namespace AdminPortal.Tests.Controller_Test.Customer
{
    [TestClass]
    public class BusinessUnitControllerTests
    {
        private IBusinessUnitRepository _mockBusinessUnitRepository;
        private BusinessUnitController _controller;

        [TestInitialize]
        public void TestInitialize()
        {
            _mockBusinessUnitRepository = MockRepository.GenerateMock<IBusinessUnitRepository>();
            _controller = new BusinessUnitController(_mockBusinessUnitRepository);
        }

        [TestCleanup]
        public void TestCleanup()
        {
            _mockBusinessUnitRepository = null;

            _controller.Dispose();
            _controller = null;

        }

        #region Index Action Tests
        [TestMethod]
        public void Index_Action_Calls_GetAllBusinessUnit()
        {
            _mockBusinessUnitRepository.Stub(x => x.GetAllBusinessUnit());

            _controller.Index();

            _mockBusinessUnitRepository.AssertWasCalled(x=>x.GetAllBusinessUnit());
        }
    }
}

When I run the project I get following screen enter image description here

I checked the references and the test project has the reference to main project. Any idea why the test are not running or saying that they were inconclusive?

Edit 1:

I saw a post here and changed my test's setting's default processor architecture to X64 but it still doesn't work.

Upvotes: 193

Views: 153443

Answers (30)

Zarepheth
Zarepheth

Reputation: 2583

Check the basics. After reading most of the 50+ answers to this question, I took a look at my test method.

Assert.Inconclusive("Unable to test. Unable to mock `DirectoryEntry` constructor.");

In other words, my own code was the cause! ( I guess this is what happens when you've not touched your code and tests for 18+ months. Then run the tests thinking everything is going to work! )

Upvotes: 0

Garry Shadow
Garry Shadow

Reputation: 46

In my case, I had two empty methods, which have the [ClassInitialize] and [ClassCleanup] attributes and the same names. I commented them out and solved the problem. Temporarily...

Upvotes: 0

Manuel Koch
Manuel Koch

Reputation: 361

For me it was a ReSharper problem, too. But non of the suggested solutions worked for me so I just updated ReSharper to the latest version and the tests functioned again.

Upvotes: 0

Midas
Midas

Reputation: 591

In case you have already installed the following nuget packages:

  • Microsoft.NET.Test.Sdk
  • MSTest.TestAdapter
  • MSTest.TestFramework

and still cannot run the tests, make sure that the .NET runtime the project is targeting is installed in your computer.

I had a fresh installation of VS2022 and all .NET Core runtimes were not installed. The test project was targeting .NET Core 2.1. Once I installed the SDK the tests could be discovered. However, it is recommended to update your projects to a long term support framework if possible.

Upvotes: 0

Teoman shipahi
Teoman shipahi

Reputation: 23052

I had to install following packages for Xunit:

enter image description here

Upvotes: 0

makeussrgreatagain
makeussrgreatagain

Reputation: 31

In my case I was using Rider and MSTest and resolved the issue by going to

Tests > Unit Testing Settings

and changing Default platform architecture from Automatic to x86

Upvotes: 0

Aleksei Zyrianov
Aleksei Zyrianov

Reputation: 2342

In my case, it was just .NET 5 runtime missing. After installing one, the problem is gone.

Upvotes: 0

granadaCoder
granadaCoder

Reputation: 27862

Gaaaa.

First a debugging tip.

I ran

dotnet test

from command line.

That told me:

MyTests does not have correct signature. Test method marked with the [TestMethod] attribute must be non-static, public, return-type as void and should not take any parameter. Example: public void Test.Class1.Test(). Additionally, if you are using async-await in test method then return-type must be Task. Example: public async Task Test.Class1.Test2()

When I went and looked.

[TestMethod]
private void MyFirstTest() 
{
}

Gaaaa.

I had it private vs public.

My fix:

[TestMethod]
public void MyFirstTest() 
{
}

Lesson learned. Check the BASICs. but the "dotnet test" told me about the basics.

Upvotes: 0

mikesigs
mikesigs

Reputation: 11380

I just fixed this issue as well. However, none of the solutions in this thread worked. Here's what I did:

Since R# wasn't giving any detail about why things were failing, I decided to try the built-in VS2013 test runner. It experienced the exact same behavior where none of the tests ran. However, looking in the Output window, I finally had an error message:

enter image description here

An exception occurred while invoking executor 'executor://mstestadapter/v1': Object reference not set to an instance of an object.

This led me to another thread on SO with a solution. Believe me, I would have NEVER guessed what the issue was.

I had recently made a few changes to the AssemblyInfo.cs file while creating a NuGet package. One of the changes including specifying an assembly culture value of "en".

I changed this:

[assembly: AssemblyCulture("")] 

to this:

[assembly: AssemblyCulture("en")]`. 

That was it! That's what inexplicably broke my unit tests. I still don't understand why, however. But at least things are working again. After I reverted this change (i.e. set the culture back to ""), my tests began running again.

Hope that helps somebody out there.

Upvotes: 8

RoboKozo
RoboKozo

Reputation: 5062

I had a version mismatch in my nuget dependencies between projects in a solution. Using the consolidate feature in Visual Studio helped identify and fix this.

Upvotes: 1

ShloEmi
ShloEmi

Reputation: 1984

Hope it'll help other, my fix was to update packages, there was a consolidation, and making all work with same packs fixed this issue for me. GL!

Upvotes: 0

Omnideth
Omnideth

Reputation: 71

I know this question has /several/ answers to it, but I have yet another unique answer that I haven't seen as a way to resolve it. I'm hoping this helps someone else out there.

To use the Unit Test Sessions, one external dependency is the Microsoft.Net.Test.Sdk, at some point in the VS pipeline the xunit.runner.visualstudio stopped working correctly for the ReSharper Unit Test Session flavor of test runner. The following is how I ended up with this problem, and how I solved it.

My issue and answer arose from seeing the Inconclusive when converting some of my net451 libraries into netStandard 2.0 in order to allow my team to develop in Core or Framework. When I went into the newly finished netStandard2.0 libraries and started converting their old unit test projects into the new solutions, I ran into issues. You can't run Unit Tests in a net Standard project, so I chose to downshift to net472 for my unit testing projects.

At this point I'll note, .csproj files have gone through a change since .net Framework. In order to cleanly integrate with build packs for nupkg files and .net Standard libraries, you need to change your references to be handled with PackageReference instead of packages.config.

I had a few libraries coupled to Windows that couldn't be converted to netStandard, so when updating their dependencies to use the new netStandard libs, I realized that the dotnet pack command would fail if their .csproj files were in the old format. To fix that, not only did they need to be converted to PackageReference from packages.config, I had to manually update the .csproj files to the newer VS2017 format. This allowed those libraries to build into nuget packages cleanly as net472 libraries referencing netStandard2.0 dependencies.

There is a tool to convert the package organization behavior for you, it keeps the old .csproj style and uses the PackageReference in the .csproj. And due to the above I got in the habit of migrating the .csproj style to the VS2017 format manually.

So in summary, I was receiving the Inconclusive when I was using both PackageReference for my dependencies AND my Unit Testing Project .csproj file was in the VS2017 style.

I was able to solve this by deleting my project, recreating it exactly as it was in net472 and instead of converting it to the VS2017 .csproj format, I left it in the old format.

The old format, for whatever reason, allows my Test Session to complete.

I'm curious of few things:

  1. If a lot of the people with this issue were experiencing it in netCore versions where the .csproj files come in the new format by default.
  2. If people able to solve the issue by other means than my reproduceable problem/fix were on the netCore versions of .csproj and using netCore as their test project as well.
  3. If this solution will help any of the people that weren't able to fix it through rebuilds or deletion of vs/bin folders or additional entries in their .csproj files.

I don't know that this answer is the one true solution that ReSharper would need to fix it for everyone, but it is reproduceable for me, and solves my problem to leave the unit test project as the old version of .csproj file, at least when I have a net472 unit test project referencing netStandard2.0 libraries.

It should also be noted that VS2017 .csproj files deprecates the need for an AssemblyInfo.cs file in the Properties folder, which I'm not sure if that causes issues for the Unit Test Sessions as well.

Upvotes: 1

yangli.liy
yangli.liy

Reputation: 101

My issue has been solved by the most superficial solution:

Add the Moq nuget package to the test project solve the inconclusive test method, and you can remove the nuget package afterwards.

After adding the Moq package my test method runs with the following nuget packages: Castle.Core (4.4.0), Moq (4.13.1), NUnit (3.12.0), System.Runtime.CompilerServices.Unsafe (4.5.0) and System.Threading.Tasks.Extensions (4.5.1)

After removing most of the above nuget packages my test method still runs with only NUnit (3.12.0).

Appreciate if someone figures out why this happens.

Upvotes: 0

Vasiliy Terkin
Vasiliy Terkin

Reputation: 165

Another one method of solving this problem:

Run tests in another environment (TeamCity for example) and see your REAL problem. My problem was incorrect binding redirect to System.Web.Mvc 5.2.6.0 (not installed on my machine).

Upvotes: 0

Cord Rehn
Cord Rehn

Reputation: 1149

For those still not able to solve their issue, check the Consolidate tab when managing your Nuget packages.

Turned out our unit test project referenced a different version causing this completely vague error.

Upvotes: 2

Alvaro Pereira
Alvaro Pereira

Reputation: 643

I had all tests from a single test class failing with this issue, all other were running well. Later I found an error in a [ignore] attribute in one the tests on this class.

Upvotes: 0

Tore Aurstad
Tore Aurstad

Reputation: 3816

In my case I had an error in my application configuration file app.config. I had misplaced appsettings above the configSections instead of placing it inside. So a corrupt configuration file could be the cause of Resharper not running your tests responding Inconclusive.

Upvotes: 0

eran otzap
eran otzap

Reputation: 12533

For me the issue was an asynchronous call which was not waited in any way.

   dc.Start(); // Asynchronous, it is mocked on this particular test, so i did not bother blocking the test.

Changed it to :

   dc.Start().ContinueWith(t =>
   {
        waitHandle.Set();
   });

   waitHandle.WaitOne(60000); // wait dc start

And the test began to be applicable again.

Upvotes: 0

navarq
navarq

Reputation: 1345

This error occurred with Visual Studio 2017 and resharper version 2018.2.3 but the fix applies to Visual Studio 2019 versions to.

The fix, to get tests working in Resharper, was simply to update to the latest version of Resharper (2019.2.1) at the time of writing.

Upvotes: 7

Albert.Qing
Albert.Qing

Reputation: 4615

enter image description here

enter image description here

Sometimes Just try drop header(.h) file and reAdd it as source(.cpp) NOT rename. Test in resharp c++ && vs2019 ,Test Code is Here

Upvotes: 0

M.Hassan
M.Hassan

Reputation: 11032

I faced this problem in vs 2017 update 3 with Resharper Ultimate 2017.2

Restart vs or restart machine can't help.

I resolved the problem by clearing the Cache as follows:

    Resharper ->options-> Environment ->click the button 'Clear caches'

Update:

There is a button "error" (I find in Resharper 2018) in the upper right corner of the test window.

If you click the error button, it shows an error message that may help in resolving the problem.

To track the root of the problem, run Visual Studio in log mode. In vs 2017, Run the command:

      devenv /ReSharper.LogFile C:\temp\log\test_log.txt /ReSharper.LogLevel Verbose

Run the test.

Review the log file test_log.txt and search for 'error' in the file.

The log file is a great help to find the error that you can resolve or you can send the issue with the log file to the technical support team of Resharper.

Upvotes: 22

Mike Olund
Mike Olund

Reputation: 429

My problem was that I had only installed NUnit with nuget. I hadn't installed NUnit3TestAdapter which was also required.

Install-Package NUnit3TestAdapter

Upvotes: 8

julio cesar
julio cesar

Reputation: 59

I'm was having the same problem to run any test using NUnit framework. "Inconclusive: Test not run" Visual Studio 2017 15.5.6

ReSharper Ultimate 2017.3.3 Build 111.0.20180302.65130

SOLVED Adding project dependency to Microsoft.NET.Test.Sdk

Upvotes: 5

Teoman shipahi
Teoman shipahi

Reputation: 23052

For who are in rush for test execution, I had to use VS 2017 test explorer to run tests;

enter image description here

enter image description here

Upvotes: 4

Danielle van Graan
Danielle van Graan

Reputation: 1

I used the ReSharper Build to fix this.

ReSharper => Options => Tools => Build => General => Use ReSharper Build

Upvotes: -1

Alessio Di Salvo
Alessio Di Salvo

Reputation: 281

If you are using xUnit, I solved the issue installing xunit.running.visualstudio package. (currently using xUnit 2.3.1 and VS17 Enterprise 15.3.5)

Upvotes: 3

Reyhn
Reyhn

Reputation: 1047

For me, the problem was a corrupt NUnit/ReSharper settings XML-file (due to an unexpected power shortage).

To identify the error I started Visual Studio with this command:

devenv.exe /ReSharper.LogFile C:\temp\resharper.log /ReSharper.LogLevel Verbose

Examining the file revealed the following exception:

09:45:31.894 |W| UnitTestLaunch                | System.ApplicationException: Error loading settings file
System.ApplicationException: Error loading settings file ---> System.Xml.XmlException: Root element is missing.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
   at System.Xml.XmlLoader.Load(XmlDocument doc, XmlReader reader, Boolean preserveWhitespace)
   at System.Xml.XmlDocument.Load(XmlReader reader)
   at System.Xml.XmlDocument.Load(String filename)
   at NUnit.Engine.Internal.SettingsStore.LoadSettings()
   --- End of inner exception stack trace ---
   at NUnit.Engine.Internal.SettingsStore.LoadSettings()
   at NUnit.Engine.Services.SettingsService.StartService()
   at NUnit.Engine.Services.ServiceManager.StartServices()
   at NUnit.Engine.TestEngine.Initialize()
   at NUnit.Engine.TestEngine.GetRunner(TestPackage package)
   at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.<>c__DisplayClass1.<RunTests>b__0()
   at JetBrains.ReSharper.UnitTestRunner.nUnit30.BuiltInNUnitRunner.WithExtensiveErrorHandling(IRemoteTaskServer server, Action action)

Note that this is NOT the test project's app.config!

A quick googling around identified the following file as the culprit:

%LOCALAPPDATA%\NUnit\Nunit30Settings.xml

It existed, but was empty. Deleting it and restarting Visual Studio solved the problem.

(Using Visual Studio Professional 2017 v15.3.5 and ReSharper 2017.2.1).

Upvotes: 13

Cybercop
Cybercop

Reputation: 8674

It was a Resharper issue. In Resharper options->Tools->MSTEST, I unchecked the Use Legacy Runner and now it works.

Upvotes: 24

Dmitry Pavlov
Dmitry Pavlov

Reputation: 28290

For those who are experiencing this issue for my test project .NET Core 2.0 in the Visual Studio 2017 Community (v15.3 3). I also had this bug using JetBrains ReSharper Ultimate 2017.2 Build 109.0.20170824.131346 - there is a bug I posted.

JetBrains advised to create a new test project from scratch to reproduce it. When I did that and got tests working OK, I found the reason causing the issue:

  • Remove this from your *.csproj file:
  • Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}"

When I did that - tests started working fine.

Upvotes: 4

Vadim
Vadim

Reputation: 21

In my case (Visual Studio Community 2017 version 15.2) the source of issue was new way of loading projects introduced in VS 2017, i.e. 'Lightweight Solution Load'.

In "Unit Test Sessions" window I noticed that solution has way less tests then it should. I had to open each unit test project manually in "Solution Explorer" and only then all tests were loaded and passed.

One way to solve this is to disable "Lightweight Solution Load" by right clicking on solution in "Solution Explorer" and set "Disable Lightweight Solution Load".

Upvotes: 0

Related Questions