本文介绍了如何捕获AssertionException和Test应该失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想处理Assert.Fail(" msg")异常,测试也会失败。

I want to handle Assert.Fail("msg") exception and test should fail as well.

推荐答案

[TestMethod]
        public void TestMethod1()
        {
           
            try

            {

                Assert.Fail("Failed because something went wrong.");

            }

            catch (AssertionException ex)

            {

                Debug.WriteLine(string.Format("Something specific went wrong.", ex));

                throw;  

            }

        }

祝你好运,

Joyce


这篇关于如何捕获AssertionException和Test应该失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-22 10:14