C# MSTest:由于未加载测试或禁用所选测试,因此未运行任何测试
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2314887/
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
MSTest: No tests are run because no tests are loaded or the selected tests are disabled
提问by gerryLowry
I have a c# solution with the following structure:
我有具有以下结构的 ac# 解决方案:
mySolution
myProject
myProject.MSTests
References
Microsoft.VisualStudio.QualityTools.UnitTestFramework
sutMSTests.cs
sutMSTests.cs:
sutMSTests.cs:
[TestClass()]
public class sutMSTests
{
[TestMethod]
public void MyTest0()
{
Microsoft.VisualStudio.TestTools.UnitTesting.Assert.AreEqual(4, 2 + 2);
}
}
When I try to run the tests via Test, Run, All Tests In Solution, I get the following on the VS2008 status line:
当我尝试通过测试、运行、解决方案中的所有测试运行测试时,我在 VS2008 状态行上得到以下信息:
No tests are run because no tests are loaded or the selected tests are disabled.
由于未加载任何测试或禁用所选测试,因此未运行任何测试。
Test, Windows, Test View shows no tests.
测试、Windows、测试视图不显示测试。
Note: I created the tests manually (works for xUnit.net) instead of using Microsoft's wizards.
注意:我手动创建了测试(适用于 xUnit.net)而不是使用 Microsoft 的向导。
I've compared my hand created MSTest setup to the setup another test that I generated using the wizard and they appear to besufficiently similar.
我已经将我手工创建的 MSTest 设置与我使用向导生成的另一个测试设置进行了比较,它们似乎非常相似。
Question:What are the most likely causes of the error message above?
问题:上述错误消息最可能的原因是什么?
Edit 2010-02-25:More information:
I right clicked the Solution Itemsfolder, and choose Add, New Project, type Test Projects,Test Documents::Visual Studio Test Project template.
编辑 2010-02-25:更多信息:
我右键单击“解决方案项”文件夹,然后选择“添加”、“新建项目”,键入“测试项目”、“测试文档”::“Visual Studio 测试项目”模板。
The new project's default do nothing test "TestMethod1" was detected and passed.
However, my test did not show up ... so I copied and pasted my test method into the default test test project "TestProject1".
检测到并通过了新项目的默认不做任何测试“TestMethod1”。
但是,我的测试没有出现......所以我将我的测试方法复制并粘贴到默认测试测试项目“TestProject1”中。
My test was detected in "TestProject" BUT not in its original location.
我的测试是在“TestProject”中检测到的,但不在其原始位置。
I closely compared the files, organization, and settings of "TestProject1" with my hand created test project.
我将“TestProject1”的文件、组织和设置与我手工创建的测试项目进行了仔细比较。
At this point, I am guessingthat some setting gets made by the Visual Studio Test Project template that is not easily detectable.
在这一点上,我猜测Visual Studio 测试项目模板进行了一些不容易检测到的设置。
imo, it should be just as easy to create a test project by hand as it is to create one with the Visual Studio Test Project template.
imo,手动创建测试项目应该与使用 Visual Studio 测试项目模板创建测试项目一样容易。
please note: I'm not saying that I'm against using the Visual Studio Test Project template; for me, I like to understand what's behind the curtain since this makes me imho a much better programmer.
请注意:我并不是说我反对使用 Visual Studio 测试项目模板;对我来说,我喜欢了解幕后是什么,因为这让我恕我直言成为一个更好的程序员。
回答by smaclell
Do you have a VSMDI file in your solution? I believe this file is required (NOT VERIFIED).
您的解决方案中有 VSMDI 文件吗?我相信这个文件是必需的(未验证)。
回答by Jason Evans
I've just manually done this:
我刚刚手动完成了这个:
Created a new C# class library project with the following code:
使用以下代码创建了一个新的 C# 类库项目:
namespace SO_Answer
{
public class Class1
{
public void Test()
{
var k = "Hello";
}
}
}
Saved the project and then went to 'File->Add->New Project' and chose 'Test Project'. After VS created the unit test project, I added a reference to the class library project I created earlier.
保存项目,然后转到“文件->添加->新建项目”并选择“测试项目”。VS创建完单元测试项目后,我添加了对之前创建的类库项目的引用。
In my test I have this code:
在我的测试中,我有这个代码:
namespace Unit_Test
{
/// <summary>
/// Summary description for UnitTest1
/// </summary>
[TestClass]
public class UnitTest1
{
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext { get; set; }
#region Additional test attributes
// You can use the following additional attributes as you write your tests:
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
#endregion
/// <summary>
/// The test method 1.
/// </summary>
[TestMethod]
public void TestMethod1()
{
var f = new Class1();
}
}
}
The only code I added was the a using statement and the var f = new Class1();
statement. Looking at the MSTest runner, I can see TestMethod1
appear.
我添加的唯一代码是 using 语句和var f = new Class1();
语句。查看 MSTest 运行程序,我可以看到TestMethod1
出现。
I can't think of a reason why your unit tests are not being picked up. The only time I've had this is because I was using the MSTest runner to try and view NUnit tests by mistake. Try starting from scratch.
我想不出为什么你的单元测试没有被接受的原因。我唯一一次遇到这种情况是因为我错误地使用 MSTest 运行程序尝试查看 NUnit 测试。尝试从头开始。
回答by Dan F
Possibly a bit late, but this question googles up well, I thought I'd throw some crumbs in for future googlers.
可能有点晚了,但是这个问题在谷歌上搜索得很好,我想我会为未来的谷歌员工扔一些面包屑。
Bryan Cook suggests checking the ProjectTypeGuids in his blog post about Manually creating a MS Test Project. Apparently the magic GUIDs you need are {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
for c# and {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}
for VB. See his blog post for more details.
Bryan Cook 建议在他关于手动创建 MS 测试项目的博客文章中检查 ProjectTypeGuids 。显然,您需要的魔法 GUID 是{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
用于 c# 和{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{F184B08F-C81C-45F6-A57F-5ABD9991F28F}
VB。有关更多详细信息,请参阅他的博客文章。
In case the blog post ever goes away you need to add the following element in the main property group in the csproj file:
如果博客文章消失了,您需要在 csproj 文件的主属性组中添加以下元素:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
回答by Dan F
Another one for the googlers - this one turned out to be my problem, and it's embarrassingly boneheaded of me. Make sure that your test project is set to build in whatever solution configuration you're using. If the test assembly isn't being built, VS won't be able to find any tests in the non-existent assembly, and you'll bang your head against the wall for a while :-)
谷歌员工的另一个问题 - 结果证明这是我的问题,这让我感到尴尬。确保您的测试项目设置为在您使用的任何解决方案配置中构建。如果未构建测试程序集,VS 将无法在不存在的程序集中找到任何测试,并且您将头撞墙一段时间:-)
回答by pradip Kr Sen
this is typical problem i have faced too. but the easiest solution I followed as my own is...just to build the project once and rebuild it again. so that you can resolve it.
这也是我遇到的典型问题。但我自己遵循的最简单的解决方案是……只构建一次项目并再次重建它。以便您可以解决它。
回答by Joy Petko
Another idea for the Googlers out there. My problem was trying to get ignored tests running again. Same MS error message occurs if you remove the Ignore label. Does not automatically re-enable the test. This article takes you through the last step. http://richallen.blogspot.com/2008/05/ms-test-re-enabling-ignored-tests.html
谷歌员工的另一个想法。我的问题是试图让被忽略的测试再次运行。如果您删除忽略标签,则会出现相同的 MS 错误消息。不会自动重新启用测试。本文将带您完成最后一步。 http://richallen.blogspot.com/2008/05/ms-test-re-enabling-ignored-tests.html
回答by Dave
This must be a bug and is an absolute pain especially as you have to reenable every single test method individually. However a bit iof lateral thinking produced a better solution - rename the test class and rebuild. Then rename it back. Seems to work. Ooops - no it doesn't. Renaming the class works but when it's renamed back it reverts to the original settings. The trick is to close down Visual Studio and delete the .vsmdi (visual studio test meta data) file. This will be regenrated.
这一定是一个错误并且绝对是一个痛苦,尤其是因为您必须单独重新启用每个测试方法。然而,有点横向思维产生了更好的解决方案 - 重命名测试类并重建。然后将其重命名。似乎工作。哎呀 - 不,它没有。重命名类有效,但当它重命名回来时,它会恢复到原始设置。诀窍是关闭 Visual Studio 并删除 .vsmdi(visual studio 测试元数据)文件。这将被重新生成。
回答by John Vetter
I was receiving the same message and it turned out to be that I had my unit test project on a network drive. Once I moved it local it ran fine. Just something to try if you get this error. John
我收到了同样的消息,结果是我在网络驱动器上有我的单元测试项目。一旦我将它移到本地,它就运行良好。如果您收到此错误,请尝试一下。约翰
回答by Marvin Bland
When you run into this issue, in Visual Studio, you have to create a Test Project. 1. Select Test in Tool bar and choose "New Test". Create your project and at this point create your test method. It should work after this point.
当您遇到此问题时,您必须在 Visual Studio 中创建一个测试项目。1. 在工具栏中选择测试,然后选择“新建测试”。创建您的项目,此时创建您的测试方法。在此之后它应该可以工作。
回答by T Jose
This could be another reason. Check whether the solution is running on 64bit. If so change it to x86.
这可能是另一个原因。检查解决方案是否在 64 位上运行。如果是这样,请将其更改为 x86。