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

匿名 (未验证) 提交于 2019-12-03 01:58:03

问题:

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();             _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

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.

回答1:

Just in case none of the above options worked for anyone I fixed my instance of this error by noticing a corrupt entry in my App.Config due to a missing nuget package in the test project.



回答2:

For me it was rather frustrating, but I've found solution for my case at least:

If your TestMethod is async, it cannot be void. It MUST return Task.

Hope it helps someone :)



回答3:

I had the same issue with resharper and I corrected this error by changing an option:

Resharper => Options => Tools => Unit Testing

I just had to uncheck the option "Shadow-copy assemblies being tested"



回答4:

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



回答5:

I was having this problem, and it turned out to be the same as this problem over here. This answer solved the problem for me.

  1. Uncheck "Only build startup projects and dependencies on Run" (Options -> Projects and Solutions -> Build and Run)
  2. In Configuration Manager, make sure both the start-up project and the Test project have "Build" checked.

The second time I hit this issue, it was due to an ampersand in the filepath to the project where the tests reside. It works fine with ReSharper's test runner, but not dotCover's. Remove the ampersand from the filepath.

This is a confirmed bug with dotCover.



回答6:

For me, simply cleaning and rebuilding the solution fixed it.



回答7:

In my case it was a mistake i did while copying the connectionstring in the app.config.. I had put it inside the configSections tag!

Took me a while to realize that... thanks VS intellisense though.. or was it resharper?



回答8:

I had similiar issue. VS 2010, c# CLR 2 Nunit 2.5.7 , just build > clean solution from VS helped to resolve this issue



回答9:

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:

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.



回答10:

In my case I created an async test method which returned void. Returning of Task instead of void solved the issue.



回答11:

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.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).



回答12:

Have you added any DLL dependency recently? ... like me

I just ran into the same issue and it was very exasperating not to get any clue in the test output window or elsewhere practical.

The cause was extremely stupid: I just added the day before dependency to an additional external DLL in a sub-project, and the main project App indeed built and ran correctly after the change. But my unit tests are in a sister project to the main app, and thus had too the dependency on this changed sub project where the DLL was invoked... yet, the runtime location of the test project is not that of the main App! So changing the build to do copying of the missing DLL into the test runtime directory fixed the problem.



回答13:

I am using VS2013, ReSharper 9.1 with MSpec extension from ReSharper and Moq. I experienced the same "inconclusive" error.

It turned out the one of my Mock's from Moq was not initialized, only declared. Ones initialized all tests ran again.



回答14:

In my case i got this error because of 'Release' mode where build of UnitTests project was simply switched off. Switching back to 'Debug' mode fixed it.

It's really surprising that ReSharper cannot say anything in case it cannot find UnitTests library at all. Seriously, it's a shame;)

Hope it will help somebody



回答15:

In my case [Test] methods were just private. S-h-a-m-e



回答16:

I'm using VS2010, NUnit 2.6.3 (although internally ReSharper says it's using 2.6.2?), ReSharper 7.7.1 & NCrunch 2.5.0.12 and was running into the same "...test is inconclusive..." thing with NUnit, but NCrunch said everything was fine. For most of today NUnit & NCrunch were in sync agreeing about which tests were happy and which needed refactoring, then something happened which I still don't understand, and for a while NCrunch said I had failing tests (but stepping through them showed them to pass), then decided they were all working, and NUnit started complaining about all my tests except one with the same message "..test is inconclusive..." which I was again able to single step through to a pass even though NUnit continued to show it as "inconclusive").

I tried several of the suggestions above to no avail, and finally just closed VS2010 & reopened the solution. Voila, now all my tests are happy again, and NCrunch & NUnit are reporting the same results again. Unfortunately I have no idea what changed to cause them to go out of sync, but closing & reopening VS2010 seems to have fixed it.

Maybe someone else will run into this and be able to use this simple (if ultimately unsatisfying since you don't know what the real fix is) solution.



回答17:

In my case, ReSharper gave me this additional exception in the test window:

2017.06.15 12:56:57.621   ERROR Exploration failed with the exception: System.AggregateException: One or more errors occurred. ---> System.Threading.Tasks.TaskCanceledException: A task was canceled.    --- End of inner exception stack trace ---    at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)    at JetBrains.ReSharper.UnitTestFramework.Launch.Stages.DiscoveryStage.Run(CancellationToken token) ---> (Inner Exception #0) System.Threading.Tasks.TaskCanceledException: A task was canceled.

it ended up that the test projects giving this error both were not set to build at all in the Configuration Manager. Checking the checkbox to build the 2 test projects and rebuilding sorted for me.



回答18:

In my case, all tests within some test projects within a solution started not running after I added new projects. Using VS 2017 with ReSharper 2017.1.2 here.

First of all, make sure you're not wasting time assuming that your issue is ReSharper related. It is easy to assume that there's something wrong with ReSharper if you use its unit testing features including Unit Test Explorer. Open up Visual Studio's Test Explorer under the Test menu and try Run All". The added advantage of doing this is that the output window will show an error message that might point you in the right direction. If you notice that the same set of test are not run, then it is safe to assume that the issue is with Visual Studio and not ReSharper.

I ended up deleting and re-adding one of the Active solution platform, Any CPU, in Configuration Manager. By doing so, after saving my changes and reopening the solution, all tests started running again.

I believe there was an unexpected configuration entry in the solution file when I added new projects and by using recreating one of the platforms, it corrected itself. I tried diffing but it was difficult to tell what had changed to cause the issue.



回答19:

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.



回答20:

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)



回答21:

I had the exact same issue and nothing helped.

eventually I saw that I had a mismatch in my namespaces of the unit project and the unit test project.

The namespace of my unit project is unit.project and the test project was named unit.project.tests but the default namespace of the test was the same as the unit, both was unit.project.

Once I've updated the namespaces to be different (one namespace for each project) everything worked!



回答22:

For me, one test created this error and it turned out I had unintentionally skipped the test. On the left of the screen, where you click to put a break point, you may notice that your test is set to be skipped (there's a microsoft icon to indicate this). I enabled the test and the error went away.



回答23:

I had the same error in VS2013 and Resharper9. The problem was because i forgot to annotate test method with [Test] :) Hope this helps anyone



回答24:

I had this same issue. The culprit was an external reference not being compatible with my project build settings. To resolve, I right clicked on the project->properties->build->Platform Target-> change from Any CPU to x86.

The particular *.dll that I was working with was System.Data.SQLite. That particular *.dll is hardcoded for 32 bit operation. The "Any CPU" setting attempted to load it as 64 bit.



回答25:

I had the exact same problem, no tests were run in my test-project. As it happend I had the wrong configuration selected when running the tests. Changing it back to Debug fixed the problems.



回答26:

In my case, I referenced 2 projects from my unittestproject. Both referenced projects used a dll with the same name, but with a different version.

I did not notice this in Visual Studio. I noticed the error in the Eventviewer.

To solve this, I used bindingRedirect in the app.config of the unittestproject to fix the dll-version.



回答27:

My solution:

NUnit 3.2.0 has some issues with Resharper - downgrade to 2.6.4:

update-package nunit -version 2.6.4 


回答28:

In my case my test method was private I changed it to public and it worked.



回答29:

Caused by missing (not corrupt) App.Config file. Adding new (Add -> New Item... -> Application Configuration File) fixed it.



回答30:

In my case found that the TestCaseSource has different number of argument than the parameter in test method.

[Test, TestCaseSource("DivideCases")] public void DivideTest(int n, int d, int q) {     Assert.AreEqual( q, n / d ); }  static object[] DivideCases = {     new object[] { 12, 3 },     new object[] { 12, 2 },     new object[] { 12, 4 }  }; 

Here each object array in DivideCases has two item which should be 3 as DivideTest method has 3 parameter.



易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!