Visual Studio 2013 没有发现单元测试 [英] Visual Studio 2013 doesn't discover unit tests

查看:24
本文介绍了Visual Studio 2013 没有发现单元测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Visual Studio 2013 中有一个简单的解决方案,它由一个 Web 项目、一个库项目和一个单元测试项目组成.当我打开解决方案并尝试运行单元测试时,它们不会被 Visual Studio 发现.要运行测试,我尝试转到菜单并选择测试 -> 运行 -> 运行所有测试或打开测试资源管理器窗口.通过这些方法,visual studio 没有发现解决方案中的任何测试.

I have a simple solution in visual studio 2013 that is composed by one web project, one library project and one unit test project. When I open the solution and try to run the unit tests they are not discover by visual studio. To run the tests I try to go to the menu and choose Test -> Run -> Run all tests or by opening the test explorer window. By those to methods visual studio doesn’t discover any tests in the solution.

首先创建一个简单的单元测试项目并尝试运行测试,visual studio 知道发现测试并且我可以运行它.然后,如果我打开以前的解决方案,visual studio 现在会发现所有测试.我尝试保存我的解决方案,但关闭它并重新打开,没有先创建单元测试项目,Visual Studio 不会再次找到测试.这是一种非常奇怪的行为,我不知道为什么会这样.

Creating first a simple unit tests project and try to run the test, visual studio know discover the test and I can run it. Then, if I open my previous solution visual studio now discovers all the tests. I try to save my solution but closing it and reopening, without creating a unit test project first, the visual studio doesn’t find the tests again. This is a very strange behave that I don’t know why this is happening.

我曾经在这个项目中单独工作,该项目使用与 Visual Studio 团队基础集成的源代码控制 git.当新元素进入项目以及我需要通过在线源代码控制重新创建解决方案时,visual studio 无法发现单元测试的问题就开始了.在此之前,所有的测试都是由visual studio 发现的.

I used to working alone in this project that was using the source control git integrated with the visual studio team foundation. The problem of visual studio not discover the unit tests start when a new element came to the project and when I need to recreate the solution through the source control online. Before this, all tests always been discovered by visual studio.

为了创建单元测试,我使用了 dll Microsoft.VisualStudio.QualityTools.UnitTestFramework.我的visual studio版本是:Microsoft Visual Studio Express 2013 for Web Version 12.0.30723.00 Update 3.我的.net framework版本是4.5.50938.

For creation the unit tests I use the dll Microsoft.VisualStudio.QualityTools.UnitTestFramework. My version of visual studio is: Microsoft Visual Studio Express 2013 for Web Version 12.0.30723.00 Update 3. My version of .net framework is 4.5.50938.

我所有的测试都是这样的:

All of my tests are like this:

[TestClass] 
public class Service1Test 
{ 
    [TestMethod] 
    public void Test1() 
    {
        Assert.IsTrue(True); 
    } 
}

推荐答案

我注意到有些事情我必须不时做才能让测试正确显示.

Some things I've noticed I have to do from time to time to get tests to show up properly.

  1. 如果您的解决方案位于需要管理员访问权限才能读/写的受保护驱动器中,有时只会出现部分测试.在这种情况下,一定要以管理员身份运行 VS.

  1. If your solution is in a protected drive that you need administrator access to read/write, sometimes only a portion of the tests come up. Definitely run VS as administrator in that case.

如果您的解决方案是 64 位,请确保测试 > 测试设置 > 默认处理器架构设置为 x64.有时它被设置为 x86.将其设置为 x64,然后重建.

If your solution is 64 bit, make sure that Test > Test Settings > Default Processor Architecture is set to x64. Sometimes it gets set to x86. Set it to x64, then rebuild.

有时只需重新启动 Visual Studio 即可解决问题,因为测试资源管理器会再次启动.

Sometimes just restarting Visual Studio does the trick because the test explorer will start up again.

不要忘记实际构建测试项目/解决方案.(如果您希望它与其余项目一起构建,请右键单击您的解决方案 > 属性 > 配置属性 > 配置 > 选中您的测试项目的构建"框)

Don't forget to actually build the test project/solution. (If you want it to get built with the rest of the projects, right-click on your solution > Properties > Configuration Properties > Configuration > check the "Build" box for your test project)

确保测试位于测试类的 public 部分

Ensure the tests are in a public section of your test class

这篇关于Visual Studio 2013 没有发现单元测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆