visual-studio Visual Studio 2010 没有发现新的单元测试

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2645442/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-22 11:46:21  来源:igfitidea点击:

Visual Studio 2010 does not discover new unit tests

visual-studio-2010visual-studiounit-testingmstest

提问by driis

I am writing some unit tests in Visual Studio 2010. I can run all tests by using "Run all Tests in Current Context".

我正在 Visual Studio 2010 中编写一些单元测试。我可以使用“在当前上下文中运行所有测试”来运行所有测试。

However, if I write a new unit test, it does not get picked up by the environment - in other words, I am not able to find it in Test List Editor, by running all tests, or anywhere else. If I unload the project and then reload it; the new test is available to run.

但是,如果我编写了一个新的单元测试,它就不会被环境接收到——换句话说,我无法在测试列表编辑器、运行所有测试或其他任何地方找到它。如果我卸载项目然后重新加载它;新的测试可以运行。

When I am adding a unit test, I simply add a new method to an already existing TestClass and decorating it with [TestMethod] attribute - nothing fancy.

当我添加一个单元测试时,我只是将一个新方法添加到一个已经存在的 TestClass 并用 [TestMethod] 属性装饰它 - 没什么特别的。

What might be causing this behaviour, and how do I make it work ?

什么可能导致这种行为,我该如何使它起作用?

回答by driis

I finally figured out the problem. In Options under Test Tools -> Test Project, there is an option "Disable background discovery of test methods". It was turned on - I do not know how that happened, but removing the checkmark and restarting Visual Studio solved the problem.

我终于想通了问题所在。在测试工具-> 测试项目下的选项中,有一个选项“禁用测试方法的后台发现”。它已打开 - 我不知道这是怎么发生的,但是删除复选标记并重新启动 Visual Studio 解决了问题。

回答by amurra

I've had this problem as well when building in debug mode. When I switched it to build in release mode that fixed it for me.

在调试模式下构建时,我也遇到了这个问题。当我将它切换到为我修复它的发布模式时。

回答by Cookie

I had a similar problem in Visual Studio 2012, however none of the solutions worked. I am developing a 64 bit application and the solution was to choose:-

我在 Visual Studio 2012 中遇到了类似的问题,但是没有一个解决方案有效。我正在开发一个 64 位应用程序,解决方案是选择:-

Test -> Test Settings -> Default Processor Architecture -> X64

回答by Dave

I've had this issue and option 2 below fixed it for me.

我遇到了这个问题,下面的选项 2 为我修复了它。

  1. Remove any app.config file (not sure why, but one of the MS forums has a few of these posts with this solution) and

  2. Ensure that within the configuration properties of the solution the project is set to build!!

  1. 删除任何 app.config 文件(不知道为什么,但 MS 论坛之一有一些与此解决方案相关的帖子)和

  2. 确保在解决方案的配置属性中将项目设置为构建!!