问题描述
这很奇怪,但是突然之间ExpectedExceptionAttribute
几天就不再为我工作了.不知道出了什么问题.我正在并行运行VS 2010和VS 2005.在VS 2010中不起作用.该测试应该通过,但是失败了:
This is weird, but all of a sudden the ExpectedExceptionAttribute
quit working for me the other day. Not sure what's gone wrong. I'm running VS 2010 and VS 2005 side-by-side. It's not working in VS 2010. This test should pass, however it is failing:
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void Test_Exception()
{
throw new ArgumentNullException("test");
}
有什么想法吗?真的很帅.
Any ideas? This really sux.
推荐答案
不是要恢复死线程,但是当我突然想到这可以帮助别人时,我遇到了这个问题.我终于找到了问题所在,这可能与乔恩发现的问题有关.仅当项目被识别为TestProject时,ExpectedException属性才会起作用. (不仅仅是.Net程序集)
Not to resurrect a dead thread, but I came across this when this all the sudden happened to me, in case it can help others. I did finally track down what the problem was, which may correlate with what Jon found. The ExpectedException attribute appears to only work if the project is recognized as a TestProject. (Not just a .Net assembly)
卸载项目,编辑csproj文件,并检查是否存在以下设置:
Unload the project, edit the csproj file and check that the following setting is there:
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
(假设为VS2010项目)重新加载项目并重建.现在,ExpectedException测试应该通过.
(Assuming VS2010 project)Reload the project and rebuild. ExpectedException tests should now pass.
我们在将测试从NUnit标准化到MSTest时遇到了这个问题(谢谢TFS CI Build),并发现在替换Assert.Throws之后,<
We ran into this issue when standardizing tests from NUnit to MSTest (Thank you TFS CI Build) and found that After replacing Assert.Throws<> beautiful simplicity & flexibility with [ExpectedException(Type)] crap, (Not to mention losing [TestCase()]!) the ExpectedException tests failed for no reason. Toggle back to NUnit with ExpectedException, no problem, MSTest refuses to run it.
不用说,在找到以下内容后,我将努力使NUnit恢复:
Needless to say I will be pushing to get NUnit back, after finding: http://blog.shawnewallace.com/2011/02/running-nunit-tests-in-tfs-2010.html
这篇关于ExpectedExceptionAttribute在MSTest中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!