Moq:测试是否抛出异常
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Moq:测试是否抛出异常相关的知识,希望对你有一定的参考价值。
The ExpectedException section under [TestMethod] is where you tell Moq what type of exception your listening for. If that exception is thrown, then this test will pass and it will stop running all the code under the target.CalculateProvisionalPrice.In case the exception isn't thrown, the Assert.Fail will throw an exception alerting you that the ArgumentNullException wasn't thrown.
[TestMethod] public void PricingService_CalculateProvisionalPrice_NullReference_Test() { // Action target.CalculateProvisionalPrice(null); Assert.Fail("Should have thrown ArgumentNullException"); }
以上是关于Moq:测试是否抛出异常的主要内容,如果未能解决你的问题,请参考以下文章
Moq:Mock.Verify()抛出NullReferenceException