如何在 Fitnesse 页面中传递任意对象?

发布于 2024-07-25 15:11:05 字数 161 浏览 3 评论 0原文

我需要在一页中的两个表之间传递一个对象(我自己的业务对象)。 该值是从一个固定装置中的 getter 调用获取的,然后应用作另一固定装置(均为 ColumnFixture)中的字段。 请注意,要传递的对象既不是原始对象也不是 String,并且转换并不那么简单。 有可能吗? 如果是这样,那又如何呢?

I need to pass an object (my own business object) between two tables in one page. The value is got from the getter call in one fixture and then should be used as field in another fixture (both ColumnFixtures). Please note that the object to be passed is neither primitive nor String and the conversion is not that simple. Is it even possible? If so, then how?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

回忆那么伤 2024-08-01 15:11:05

假设您有两个列固定表,例如:

|TableOne            |
|inputOne|outputOne()|
|7       |14         |

然后

|TableTwo            |
|inputTwo|outputTwo()|
|6       |20         |

在相应的代码中,您可以存储您希望在静态变量中传递的对象(我在这里使用 int 但任何类型都可以) :

public class TableOne extends fit.ColumnFixture {
    public static int result;
    public int inputOne;
    public int outputOne() {
        result = inputOne * 2;
        return result;
    }
}

public class TableTwo extends fit.ColumnFixture {
    public int inputTwo;
    public int outputTwo() {
        return TableOne.result + inputTwo;
    }
}

不过,我建议您不要使用 ColumnFixture s,而是查看 Rick Mugridge 的 fitlibrary(特别是 DoFixture),它允许装置以更优雅的方式进行通信。

Supposing you have two column fixture tables such as:

|TableOne            |
|inputOne|outputOne()|
|7       |14         |

and

|TableTwo            |
|inputTwo|outputTwo()|
|6       |20         |

then in the corresponding code you can store the object you wish to pass in a static variable (I'm using an int here but any type will work):

public class TableOne extends fit.ColumnFixture {
    public static int result;
    public int inputOne;
    public int outputOne() {
        result = inputOne * 2;
        return result;
    }
}

public class TableTwo extends fit.ColumnFixture {
    public int inputTwo;
    public int outputTwo() {
        return TableOne.result + inputTwo;
    }
}

Instead of using ColumnFixtures, however, I recommend that you look into Rick Mugridge's fitlibrary (in particular DoFixture) which allows fixtures to communicate in a more elegant way.

快乐很简单 2024-08-01 15:11:05

我会检查一下 Fitlibrary,谢谢。
与此同时,我刚刚找到了不同的、可能更好的方法:

使用 fit API 并将值保存到符号映射中。 您可以通过常规字段设置地图的键,然后像这样检索它:Fixture.setSymbol(...),然后是 Fixture.getSymbol(...)。
上面提到的方法也是静态的,但这种方法提供了更多的灵活性,因为变量值不是硬连接在代码中,而是在映射中索引:-)

I'll check the fitlibrary, thanks.
In the meantime, I have just found different and possibly better way:

use the fit API and save the value into the symbols map. You can just set the key for the map via regular field and then retrieve it like this: Fixture.setSymbol(...) and then Fixture.getSymbol(...).
The above mentioned methods are static as well, but this approach offers a bit more flexibility, because the variable value is not hard wired in the code, but rather indexed in a map:-)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文