MSTEST-断言失败后继续 [英] MSTEST - Continuing after an Assert has failed

查看:107
本文介绍了MSTEST-断言失败后继续的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道在断言失败之后是否有一种简单的方法来完成测试.我们曾经使用Galileo进行所有自动化测试,但是我们已经移走了Visual Studio Test框架.我们有一种方法可以使测试失败,但可以继续进行下去.

I am wonder if there is an easy way to finish a test after an Assert has failed. We used to use Galileo for all of our automated tested, but we have moved the Visual Studio Test framework. We had a method that would allow a test to fail, but continue on.

        public static bool DoAssertAndContinue(Action assert)
    {
        try
        {
            assert();
            return true;
        }
        catch (AssertionException ae)
        {
            ConfigContext.WriteLine(ae.Message);
            return false;
        }
    }

这是我们以前使用过的...它将被这样称呼:

This is what we used before...and it would be called like this:

assertionResults.Add(Automation.Utils.CommonMethods.DoAssertAndContinue(() => Assert.IsTrue(detail.ValidateName(boo, urns))));

我只是想找出仿效以前的最佳方法,而不必重构所有测试.

I am just trying to figure out the best way to emulate what we had before without having to refactor all of our tests.

推荐答案

您现在应该捕获

Instead of AssertionException, you should now catch UnitTestAssertException which is the base exception for all mstest assert failures.

这篇关于MSTEST-断言失败后继续的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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