C# 测试方法不确定:未运行测试。错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18311108/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Test method is inconclusive: Test wasn't run. Error?
提问by Cybercop
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
当我运行项目时,我得到以下屏幕
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:
编辑1:
I saw a post hereand changed my test's setting's default processor architecture to X64 but it still doesn't work.
我在这里看到了一个帖子,并将我的测试设置的默认处理器架构更改为 X64,但它仍然不起作用。
采纳答案by Cybercop
It was a Resharper issue. In Resharper options->Tools->MSTEST, I unchecked the Use Legacy Runner and now it works.
这是一个 Resharper 问题。在 Resharper options->Tools->MSTEST 中,我取消选中 Use Legacy Runner,现在它可以工作了。
回答by Elias Platek
I had the same issue with resharper and I corrected this error by changing an option:
我在 resharper 上遇到了同样的问题,我通过更改一个选项纠正了这个错误:
Resharper => Options => Tools => Unit Testing
Resharper => 选项 => 工具 => 单元测试
I just had to uncheck the option "Shadow-copy assemblies being tested"
我只需要取消选中“正在测试的阴影复制程序集”选项
回答by Mike Chamberlain
For me, simply cleaning and rebuilding the solution fixed it.
对我来说,只需清洁和重建解决方案即可修复它。
回答by Chris Pacey
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.
以防万一上述选项都不适用于任何人,我通过在我的 App.Config 中注意到由于测试项目中缺少 nuget 包而损坏的条目来修复此错误的实例。
回答by Abdul Jabbar
I had similiar issue. VS 2010, c# CLR 2 Nunit 2.5.7 , just build > clean solution from VS helped to resolve this issue
我有类似的问题。VS 2010, c# CLR 2 Nunit 2.5.7 , just build > clean solution from VS 有助于解决这个问题
回答by mikesigs
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:
由于 R# 没有提供有关失败原因的任何详细信息,我决定尝试使用内置的 VS2013 测试运行程序。它经历了完全相同的行为,没有运行任何测试。但是,在“输出”窗口中查看时,我终于收到了一条错误消息:
An exception occurred while invoking executor 'executor://mstestadapter/v1': Object reference not set to an instance of an object.
调用执行程序“executor://mstestadapter/v1”时发生异常:未将对象引用设置为对象的实例。
This led me to another thread on SOwith a solution. Believe me, I would have NEVER guessed what the issue was.
这让我找到了另一个关于 SO 的线程并提供了解决方案。相信我,我永远不会猜到问题是什么。
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".
我最近在创建 NuGet 包时对 AssemblyInfo.cs 文件进行了一些更改。其中一项更改包括将程序集文化值指定为“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.
希望能帮助那里的人。
回答by delliottg
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").
我正在使用 VS2010、NUnit 2.6.3(尽管 ReSharper 在内部说它使用的是 2.6.2?)、ReSharper 7.7.1 和 NCrunch 2.5.0.12 并且遇到了同样的“......测试不确定......”的事情使用 NUnit,但 NCrunch 说一切都很好。在今天的大部分时间里,NUnit 和 NCrunch 都一致同意哪些测试是满意的,哪些需要重构,然后发生了一些我仍然不明白的事情,有一段时间 NCrunch 说我有失败的测试(但逐步通过它们表明他们通过),然后决定它们都在工作,然后 NUnit 开始抱怨我的所有测试,除了一个带有相同消息“..test is unconclusive ...”的测试,即使 NUnit 继续,我也能够再次单步通过将其显示为“不确定”)。
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.
我尝试了上面的几个建议都无济于事,最后只是关闭了VS2010并重新打开了解决方案。瞧,现在我所有的测试都再次愉快了,并且 NCrunch 和 NUnit 再次报告了相同的结果。不幸的是,我不知道是什么改变导致它们不同步,但是关闭并重新打开 VS2010 似乎已经修复了它。
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.
也许其他人会遇到这个问题并且能够使用这个简单的(如果最终不满意,因为你不知道真正的修复是什么)解决方案。
回答by Kcats Wolfrevo
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!
就我而言,这是我在 app.config 中复制连接字符串时犯的一个错误。我将它放在 configSections 标签中!
Took me a while to realize that... thanks VS intellisense though.. or was it resharper?
我花了一段时间才意识到……虽然感谢 VS intellisense ……还是它更清晰?
回答by silver
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.
我的单元项目的命名空间是unit.project,测试项目被命名为unit.project.tests,但测试的默认命名空间与单元相同,都是unit.project。
Once I've updated the namespaces to be different (one namespace for each project) everything worked!
一旦我将命名空间更新为不同的(每个项目一个命名空间),一切正常!
回答by berhauz
Have you added any DLL dependency recently? ... like me
您最近是否添加了任何 DLL 依赖项?... 像我这样的
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.
原因非常愚蠢:我刚刚在子项目中添加了对额外外部DLL的依赖的前一天,并且主项目App确实在更改后正确构建并运行。但是我的单元测试在主应用程序的姊妹项目中,因此也依赖于调用 DLL 的这个更改的子项目......然而,测试项目的运行时位置不是主应用程序的位置!因此,更改构建以将丢失的 DLL 复制到测试运行时目录中解决了该问题。