我有一些测试是使用Microsoft.VisualStudio.TestTools内置的。单元测试,但不能让它们运行。

我使用visual studio 2012终极版。

我有两个项目的解决方案;一个有测试,使用Microsoft.VisualStudio.TestTools。UnitTesting, [TestClass]在类之前,[TestMethod]在测试方法之前,并参考Microsoft.VisualStudio.QualityTools.UnitTestFramework(版本10.0.0.0,运行时版本v2.0.50727)。我已经尝试过。net框架3.5,4和4.5其他人给出了一个重定向错误。

我已经尝试构建解决方案和项目。测试资源管理器显示“构建解决方案以发现所有可用的测试”。单击“全部运行”可在解决方案中构建、发现和运行所有测试。

问题是:如何让visual studio找到测试?


我也试过遵循这个:http://msdn.microsoft.com/en-US/library/ms379625%28v=VS.80%29.aspx但没有成功:当我被要求右键单击并选择创建测试时,我被困在了开始的部分。没有创建测试。


我有这个测试(它编译,但不显示在测试资源管理器):

using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace tests {
    [TestClass]
    public class SimpleTest {
        [TestMethod]
        public void Test() {
            Assert.AreEqual("a","a", "same");
        }
    }
}

我现在发现(见下面删除的答案),这是因为它在一个共享驱动器上,但我还不知道如何绕过它。(可能是关于安全设置的问题)。


当前回答

另一个可能阻止发现测试的问题,通常在“测试”输出窗口中会出现如下消息:

Failed to configure settings for runsettings plugin 'VSTest Run Configuration' as it threw following exception:
'An error occurred while parsing EntityName. Line 1, position 8.'
Please contact the plugin author.

这可能是因为路径或文件名中的字符需要转义才能解析为xml。特别是&字符,如<和>不允许出现在目录或文件名中。这将导致测试发现出错,无法识别测试,但我仍然可以通过单击空白处的Resharper手动运行测试。

其他回答

I found the best way to troubleshoot this issue is to create a .proj msbuild file and add your unit test projects which you hare having an issue into this file and execute the tests using the command line version of mstest. I found a small configuration issue in my app.config which only appeared when running the tests from mstest - otherwise the test project built just fine. Also you will find any indirect reference issues with this method as well. Once you can run the Unit test from the command line using mstest you can then do a clean solution, rebuild solution and your test should be discovered properly.

对我来说,解决方案没有那么复杂。

我只是把一个现有的解决方案带到我的机器上(从gitHub克隆),我们不跟踪Visual Studio创建的自动生成的.cs文件。(每个特性文件都有一个同名的。cs文件)

在没有关联的.cs文件的情况下打开解决方案实际上允许我导航到绑定的方法,因此specflow似乎正确地连接起来了,但我无法在test Explorer中查看测试名称。

对于这个问题,简单地从项目中排除特性文件,然后重新包含它们,迫使VS重新生成这些自动生成的代码隐藏文件。

之后,我就可以在测试资源管理器中查看测试了。

请将关键字public添加到类定义中。您的测试类目前在其自身程序集之外不可见。

namespace tests {
    [TestClass]
    public class SimpleTest {
        [TestMethod]
        public void Test() {
            Assert.AreEqual("a","a", "same");
        }
    }
}

Visual Studio Professional 2012,更新4。将互操作函数定义(DllImport/extern)作为测试类放在同一个项目中会使测试资源管理器感到困惑。将Interop移到一个单独的项目中,解决了这个问题。

从菜单栏顶部…

Test ->执行->所有测试

也可以从“测试资源管理器”查看所有测试(“测试-> Windows ->测试资源管理器”)

进一步的VS 2012,如果你错过了什么,尝试使用快速启动栏在右上方搜索(Ctrl + Q)“测试”

希望这能有所帮助。