格式化 Fitnesse RowFixture 中的数据
我有一个 Fitnesse RowFixture,它返回业务对象列表。 该对象有一个字段,它是一个浮点数,表示 0 到 1 之间的百分比。业务对象的消费者将是来自设计者的网页或报表,因此百分比的格式将由设计师而不是业务对象决定。
如果页面能够模仿设计者将数字转换为百分比,即不显示 0.5,而是显示 50%,那就更好了。 但我不想用显示代码污染业务对象。 有没有办法在 RowFixture 中指定格式字符串?
I've got a Fitnesse RowFixture that returns a list of business objects. The object has a field which is a float representing a percentage between 0 and 1. The consumer of the business object will be a web page or report that comes from a designer, so the formatting of the percentage will be up to the designer rather than the business object.
It would be nicer if the page could emulate the designer when converting the number to a percentage, i.e. instead of displaying 0.5, it should display 50%. But I'd rather not pollute the business object with the display code. Is there a way to specify a format string in the RowFixture?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您当然不想仅仅为了让测试看起来更好而修改业务逻辑。 不过,好消息是,有一种方法可以完成此任务,该方法并不困难,但不像传递格式说明符那么容易。
尝试将您的 Fit Fixture 视为 FitNesse 和您的应用程序代码之间的服务边界。 您想要定义一个不一定需要更改的合同,如果您的SUT(S系统下
测试)改变。让我们看一下业务对象的简化版本:
由于 RowFixture 的工作方式,我们需要定义一个将作为契约工作的简单对象。 通常我们会使用一个接口,但这并不能满足我们的目的,因此一个简单的DTO(DataT传输 >Oobject) 就足够了。
像这样的事情:
现在我们可以定义一个 RowFixture,它将返回我们的自定义 DTO 对象的列表。 我们还需要创建一种将 BusinessObject 转换为 ReturnRowDTO 的方法。 我们最终得到了一个看起来像这样的夹具。
现在,您可以更改基础 BusinessObjects,而不会破坏实际的适合度测试。 希望这可以帮助。
You certainly don't want to modify your Business Logic just to make your tests look better. Good news however, there is a way to accomplish this that is not difficult, but not as easy as passing in a format specifier.
Try to think of your Fit Fixture as a service boundary between FitNesse and your application code. You want to define a contract that doesn't necessarily have to change if the implementation details of your SUT (System Under Test) change.
Lets look at a simplified version of your Business Object:
Becuase of the way that a RowFixture works we need to define a simple object that will work as the contract. Ordinarily we would use an interface, but that isn't going to serve our purpose here so a simple DTO (Data Transfer Object) will suffice.
Something Like This:
Now we can define a RowFixture that will return a list of our custom DTO objects. We also need to create a way to convert BusinessObjects to ReturnRowDTOs. We end up with a Fixture that looks something like this.
You can now change your underlying BusinessObjects around without breaking your actual Fit Tests. Hope this helps.
我不确定“污染”是什么。 要么要求您的业务对象返回一个以百分比表示的值,在这种情况下,您的业务对象应该提供该值,要么您正在测试您现在拥有的浮动响应的真实值。
试图让 Fitnesse 来提高可读性的价值似乎有点奇怪。
I'm not sure what the "polution" is. Either the requirement is that your Business Object returns a value expressed as a percentage, in which case your business object should offer that -OR- you are testing the true value of the response as float, which you have now.
Trying to get fitnesse to massage the value for readability seems a bit odd.