apache-flex - 为什么 FlexUnit 中没有 assertError() 函数?

标签 apache-flex actionscript-3 error-handling assertions flexunit

似乎大多数 XUnit 测试框架在您想要断言给定操作将引发异常(或 AS3 说法中的错误)时提供断言。会解释没有包含在 FlexUnit 中的 assertError() 断言吗?

我知道如何实现这样的东西,我可能会将它添加到我的 FlexUnit(去开源!),但这似乎是一个如此明显的遗漏,我不知道我是否只是做错了。

有人对此有什么想法吗?

最佳答案

2010 年 5 月 2 日编辑:我现在建议使用 FlexUnit 4 .它使用可扩展的元数据系统,支持预期异常,还支持在不使用 AIR 的情况下在集成服务器环境中运行。

编辑:你应该看看fluint ,它是由受够了 FlexUnit 及其局限性的人构建的。它可能内置了其中一些类型的断言。

我完全同意。事实上,FlexUnit 缺少几个有用的方法(assertEvent、assertArrayEquals 等)。我知道你说过你知道如何实现它,但请随意使用我的:

public static function assertError(message : String, func : Function, errorClass : Class = null, errorMessage : String = null, errorCodes : Array = null) : Error 
{
    _assertionsMade++;

    if (errorClass == null) errorClass = Error;

    try
    {
        func();
    }
    catch(ex : Error)
    {
        if (!(ex is errorClass))
        {
            fail("Expected error of type '" + getQualifiedClassName(errorClass) + "' but was '" + getQualifiedClassName(ex) + "'");
        }

        if (errorMessage != null && ex.message != errorMessage)
        {
            fail("Expected error with message '" + errorMessage + "' but was '" + ex.message + "'");
        }

        if (errorCodes != null && errorCodes.indexOf(ex.errorID) == -1)
        {
            fail("Expected error with errorID '" + errorCodes.join(" or ") + "' but was '" + ex.errorID + "'");
        }

        return ex;
    }

    if (message == null)
    {
        message = "Expected error of type '" + getQualifiedClassName(errorClass) + "' but none was thrown"
    }

    fail(message);

    return null;
}

关于apache-flex - 为什么 FlexUnit 中没有 assertError() 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/607136/

相关文章:

actionscript-3 - 在函数外部使用变量。错误-参数数目不正确。预期1

actionscript-3 - 采用 HMACSHA512 加密的 AS3 Air 应用程序

javascript - 当没有数据来自API时如何在React中向用户显示错误消息

ruby-on-rails - Rails 中的 404 静态错误页面,公共(public)资源的路径上下文根据请求 URI 变化

java - Tomcat 在一个月不活动后关闭连接 - 如何避免?

android - 用 Flex 编写的 Facebook 应用程序的 "Android Class Name"是什么?

Flash 编程器 : how do you make your code decompile proof?

vb.net - mscorlib.dll-DateTime中发生“System.FormatException”

apache-flex - Flex 4.5.1 查看状态转换,如何针对移动设备进行优化

apache-flex - Flex : Wrapper for ResourceManager. getInstance().getString 未收到 localeChain 更新通知