如何在 Fitnesse 页面中传递任意对象?
我需要在一页中的两个表之间传递一个对象(我自己的业务对象)。 该值是从一个固定装置中的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您有两个列固定表,例如:
然后
在相应的代码中,您可以存储您希望在静态变量中传递的对象(我在这里使用
int
但任何类型都可以) :不过,我建议您不要使用 ColumnFixture s,而是查看 Rick Mugridge 的 fitlibrary(特别是
DoFixture
),它允许装置以更优雅的方式进行通信。Supposing you have two column fixture tables such as:
and
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):Instead of using
ColumnFixture
s, however, I recommend that you look into Rick Mugridge's fitlibrary (in particularDoFixture
) which allows fixtures to communicate in a more elegant way.我会检查一下 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:-)