【问题标题】:Fitnesse - Map exception to failureFitnesse - 将异常映射到失败
【发布时间】:2018-02-15 20:23:39
【问题描述】:

情况:我们的客户设计为在一切正常时运行(无效)并在出现不良情况时抛出专门的异常(例如,使用已经存在的用户名注册用户)。

我们正在使用Slim Decision Tables。一个示例夹具如下所示:

public class MyFixture {

    private final Client client;
    private String someKey;
    private String accessToken;

    public MyFixture() {
        client = initClient();
    }

    public void setSomeKey(final String someKey) {
        this.someKey = someKey;
    }

    public void setAccessToken(final String accessToken) {
        this.accessToken = accessToken;
    }

    public final void execute() {
        // this execution may throw an Exception that inherits from RuntimeException 
        // and contains a String field called errorCode which can validate against
        client.executeFailableRequest(someKey, accessToken);
    }
}

问题:Fitnesse 将异常显示为黄色,但我希望将它们视为红色失败。这可能吗?

我们知道捕获异常并评估其内容是可能的,但更喜欢体积较小的方法。

【问题讨论】:

  • 您能否详细说明您的客户是如何连接到 FitNesse 的?我的意思是:你使用 Fit 或 Slim 作为测试系统,你使用什么样的桌子,你的灯具是什么样的?
  • 添加了更多细节。

标签: fitnesse


【解决方案1】:

我不相信您可以在决策表的 execute() 方法中将一行设为红色。但是您可以在那里捕获异常并在您的表中明确评估是否引发错误。比如:

public class MyFixture {

    private final Client client;
    private String someKey;
    private String accessToken;
    private String lastError;

    public MyFixture() {
        client = new Client();
    }

    public void setSomeKey(final String someKey) {
        this.someKey = someKey;
    }

    public void setAccessToken(final String accessToken) {
        this.accessToken = accessToken;
    }

    public final void execute() {
        try {
            // this execution may throw an Exception that inherits from RuntimeException
            // and contains a String field called errorCode which can validate against
            client.executeFailableRequest(someKey, accessToken);
            lastError = null;
        } catch (MyError e) {
            lastError = e.getErrorCode();
        }
    }

    public String errorCode() {
        return lastError;
    }
}

和桌子

|my fixture                      |
|some key|access token|errorCode?|
|key     |a           |null      |
|a       |b           |null      |

如果错误/异常可以由许多方法引发(即,您不能只在 execute 方法中添加 try/catch,但必须在许多方法中这样做),您可以让您的夹具实现 @987654326 @。这允许您“拦截”从 Slim 到您的夹具的所有调用并添加自定义处理(例如应用于所有调用的方面)。

您还可以考虑将您的夹具重写为 'table table',它可以更多/完全控制您的表的评估方式。然后你选择哪些颜色给哪些单元格。

最后一种方法是实现您自己的 Slim 表,而不是使用决策表,但根据我的经验,这可能非常复杂,而且对于手头的问题似乎有点过头了。

【讨论】:

    猜你喜欢
    • 2013-08-17
    • 2019-12-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-01-05
    • 1970-01-01
    相关资源
    最近更新 更多