[英]Visual Studio test project with MSTest tests reports “the project does not contain any tests”--though it does
I have a Visual Studio 2010 solution with several projects, including .NET4 test projects. 我有一个包含多个项目的Visual Studio 2010解决方案,其中包括.NET4测试项目。 One such project, when I try to run it without debugging (Ctrl+F5), reports: 当我尝试在不调试的情况下运行它时,其中一个这样的项目(Ctrl + F5)报告:
"Cannot start test project MyTestProject because the project does not contain any tests." “无法启动测试项目MyTestProject,因为该项目不包含任何测试。”
But, the project has several tests. 但是,该项目有几个测试。 Each test class is marked with the [TestClass] attribute, and each test method within is marked with the [TestMethod] attribute. 每个测试类都标记有[TestClass]属性,并且每个测试方法都标有[TestMethod]属性。 Just to demonstrate my own sanity, I added this file and it still wouldn't recognize that there are tests. 只是为了展示自己的理智,我添加了此文件,但它仍然不知道有测试。
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Foo {
[TestClass]
public class UnitTest1 {
[TestMethod]
public void TestMethod1() {
}
}
}
The project is properly set as a test C# project. 该项目已正确设置为测试C#项目。 The tests in question also fail to show up in the Test List Editor's "Tests not in a list" section. 有问题的测试也无法显示在“测试列表”编辑器的“不在列表中的测试”部分中。 (I translated most of the tests from VB.) (我翻译了VB的大部分测试。)
Why isn't Visual Studio recognizing the tests? 为什么Visual Studio无法识别测试? How could I troubleshoot it? 我该如何解决?
Turns out that these tests were translated to C# from VB; 原来,这些测试已从VB转换为C#。 when I translated them, I forgot to add explicit namespaces on them. 翻译它们时,我忘记在它们上添加显式名称空间。 Thus there were two test classes in the global namespace with the same name, which caused one to effectively replace the other. 因此,全局命名空间中有两个名称相同的测试类,这导致一个类有效地替换了另一个。 I just wish the warning given was a little less cryptic! 我只是希望给出的警告少一些神秘!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.