【问题标题】:Concordion - how can i set a value into a table?Concordion - 我如何在表格中设置一个值?
【发布时间】:2014-02-06 18:26:04
【问题描述】:

在我进行的协和测试的某个阶段,我将一个值设置为某个随机数。

这个值被传递,稍后,我有一些输出。使用 concordion“表”设置“检查”输出,我将输出值与我期望的值进行比较。

我的问题是我想检查上面提到的随机数。当我得到随机数时,我可以将它设置为 Concordion 可以存储的东西 -

<span c:set="#prefixValue">Bob</span>

好吧,你明白了 - 我用一个吸气剂代替“鲍勃”,以获得我的价值。

但是当我尝试使用它时:

<table c:execute="#actual = getValue(#report, #xpath)">
    <tr>
        <th>Field name</th>
        <th c:assertEquals="#actual">Value</th>
        <th c:set="#xpath">Xpath</th>
    </tr>
    <tr>
        <td>UnrelatedValue</td>
        <td>SomeDeterminateValue</td>
        <td>theXpathForThisToCompareTo</td>
    </tr>
    <tr>
        <td>prefix</td>
        <td><span c:echo="#prefixValue" /></td>
        <td>differentXpathForThisToCompareTo</td>
    </tr>

整个shebang都停了下来,抱怨着

" 在

上使用 'execute' 或 'verifyRows' 命令时,必须将命令放在元素上。 "

如何在 Concordion 的表格中使用预先确定的值?

【问题讨论】:

    标签: concordion


    【解决方案1】:

    规范中不应包含随机元素。它们应该包含一个特定的示例或一组示例。与其使用随机数,不如硬编码一个特定的值,然后您可以在以后使用它。

    要告诉夹具硬编码的值,您可以这样做:

    <span c:execute="setPrefixValue(#TEXT)">Bob</span>
    

    然后在夹具中:

    public void setPrefixValue(String prefixValue) {
        // TODO: Whatever system configuration you need to do
    }
    

    如果实际上无法在您的被测系统中设置该值,则使用您的夹具代码在硬编码值和实际随机值之间进行映射。

    public String getValue(String report, String xpath) {
        String value = report(report).get(xpath);
        if (value.equals(knownRandomValue)) {
            return hardcodedValue;
        }
        return value;
    }
    

    【讨论】:

    • 有趣的想法,最后我只是推出了自己的比较器。仍然不明白为什么我不能拥有我在其他地方保存的价值(我的意思是开箱即用)-对我来说似乎很弱。
    • 这违背了 Concordion 的“不要在规范中做任何花哨的事情”的一般理念。这些规范旨在类似于静态文档,而不是 JSP。
    【解决方案2】:

    主啊!我没有意识到 Concordion 会对我变得僵硬。

    为了解决这个问题,我不得不改变我使用的 Concordion 方法,使其不那么愚蠢。

    按照这里的总体思路: http://automatingsoftwaretesting.wordpress.com/2011/05/27/write-your-own-concordion-command-an-example-for-asserting/

    这是我写的:

    @Override
    public void verify(CommandCall commandCall, Evaluator evaluator, ResultRecorder resultRecorder) {
        Object expected = evaluator.evaluate(commandCall.getChildren().get(0).getExpression());
        Object actual = evaluator.evaluate(commandCall.getExpression());
    
        Element element = setupTheGoshDarnElement(commandCall, expected);
    
        if (actual.equals(expected)) {
            resultRecorder.record(Result.SUCCESS);
            announceSuccess(element);
        } else {
            resultRecorder.record(Result.FAILURE);
            announceFailure(element, expected.toString(), actual);
        }
    }
    
    private Element setupTheGoshDarnElement(CommandCall commandCall, Object expected) {
        Element e = commandCall.getElement();
        e.appendText(expected.toString());
        return e;
    }
    
    private void announceFailure(Element element, String expected, Object actual) {
        listeners.announce().failureReported(new AssertFailureEvent(element, expected, actual));
    }
    
    private void announceSuccess(Element element) {
        listeners.announce().successReported(new AssertSuccessEvent(element));
    }
    

    因此创建了一个新的“评估器”~ 如果您想知道的话,评估器的其余部分与 AssertEqualsCommand 相同。

    这会巧妙地检查元素并进行评估。为什么 concordion 不这样做呢~这根本不是火箭科学~超出我的想象!

    请注意,我仍然需要在我的问题中使用“扩展表”才能使其正常工作,短表在评估内部表达式方面存在其自身的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-29
      • 2019-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-17
      • 1970-01-01
      相关资源
      最近更新 更多