简体   繁体   English

带有MSTest测试的Visual Studio测试项目报告“该项目不包含任何测试”-尽管它包含

[英]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.

相关问题 Visual Studio 2010中的MsTest忽略了来自测试程序集的测试 - MsTest in Visual Studio 2010 ignoring tests from a test assembly MSTest将于2010年停止在测试项目之外进行调试测试 - MSTest stops debugging tests outside test project in 2010 TFS 2010 RC无法运行Visual Studio 2008 MSTest单元测试 - TFS 2010 RC does not run Visual Studio 2008 MSTest unit tests MSTest 不执行单元测试 - MSTest does not execute unit tests 测试项目无法在Visual Studio 2010中打开 - Test project does not open in visual studio 2010 Visual Studio不会在测试类中运行所有单元测试 - Visual Studio does not run all the unit tests in a test class Visual Studio安装程序项目,该项目安装先决条件但不包含先决条件 - Visual studio setup project which installs prerequisites but does not contain them Visual Studio编码的UI测试,如何使测试在同一测试项目中以不同的设置/清除脚本运行? - Visual studio Coded UI test, how to make tests run with different setup/cleanup scripts in the same test project? Visual Studio /mstest 如何识别测试项目? - How does Visual Studio /mstest identify test projects? Visual Studio Test Essentials / Test Runner是否运行Web和负载测试? - Does Visual Studio Test Essentials/Test Runner run web & load tests?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM