ExpectedException消息参数不起作用! [英] ExpectedException message parameter does not work!

查看:283
本文介绍了ExpectedException消息参数不起作用!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下测试不会失败。我错过了什么吗?


The following test does not fail. Am I missing something?

        [TestMethod]
        [ExpectedException( typeof( System.ArgumentException), "This is the WRONG exception message.")]
        public void ExpectedExceptionDoesntDetectWrongMessage()
        {
            ThrowException();
        }

        private void ThrowException()
        {
            throw new System.ArgumentException("This is the exception message.");
        }


Rick Harrison(KnowWare,Inc。)


Rick Harrison (KnowWare, Inc.)

推荐答案

为什么你会期望它失败?

从我所看到的,它抛出了预期的异常。

请注意,ExpectedException构造函数的第二个参数是无关的抛出异常。相反,它与Assert.IsTrue相同,这意味着如果出现问题(您没有获得例外异常),它将出现在测试结果中。那是你在看什么?

希望这会有所帮助。

Why would you expect this to fail?

From what I can see, it throws the expected exception.

Note that the second parameter of the ExpectedException constructor is NOT related to the thrown exception. Rather, it is the same as with Assert.IsTrue meaning that it  is the text that will appear in the test results if there is a problem (you don't get  the excepted exception). Is that what you were looking at?

Hope this helps.


这篇关于ExpectedException消息参数不起作用!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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