“单元测试"一份报告 [英] "Unit testing" a report

查看:59
本文介绍了“单元测试"一份报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何对由 Crystal Reports 或 SQL Server Reporting Services 等报表引擎创建的报表进行单元测试"?

How would you "unit test" a report created by some report engine like Crystal Reports or SQL Server Reporting Services?

推荐答案

报告的问题类似于 GUI 的问题.如果报告/GUI 有很多(错位的)智能,就会使测试变得困难.那么解决方案是

The problem with reports is akin to the problem with GUIs. If the Report/GUI has lot of (misplaced) intelligence it is going to make testing difficult. The solution then is to

  • 分离展示:分离展示与内容(数据访问/域/业务规则).在当前上下文中,您创建某种反映最终报告内容的 ViewModel 类(例如,如果您的报告中有订单详细信息和行项目,该类应该具有详细信息的属性和行列表项对象).ViewModel 的测试极其简单.最后一英里,将呈现应用到内容应该相对简单(薄 UI).
    例如如果您使用 xslt 来呈现您的报告,您可以使用 XmlUnit 或字符串比较等工具测试数据 xml.您可以对最终报告的数据 xml 的 xsl 转换有合理的信心......此外,这里的任何错误都可以轻松修复.
  • 但是,如果您使用 Crystal Reports 等第三方供应商,则您无法控制/访问挂钩到报告生成.在这种情况下,您能做的最好的事情就是生成称为 Golden Files 的代表性/预期输出文件(例如 pdf).在测试中将此用作只读资源以比较实际输出.然而,这种方法非常脆弱......因为对报告生成代码的任何实质性更改都可能导致所有以前的黄金文件不正确.所以他们必须重生.如果自动化的成本效益比太高,我会说带有老式 word doc 测试计划的 Go 手册.
  • Separated Presentation : Separate presentation from content (data-access/domain/business rules). In the current context would mean, that you create some sort of ViewModel class that mirrors the content of the final report (e.g. if you have order details and line items in your report, this class should have properties for the details and a list of line item objects). The ViewModel is infinitely simpler to test. The last-mile, applying presentation to the content should be relatively trivial (thin UI).
    e.g. if you use xslt to render your reports, you can test the data xml using tools like XmlUnit or string compare. You can reasonable confident in xsl transformations on the data xml for the final report... Also any bugs in here would be trivial to fix.
  • However if you're using third party vendors like Crystal Reports, you have no control / access to hook in to the report generation. In such cases, the best you can do is generate representative/expected output files (e.g. pdfs) called Golden Files. Use this as a read-only resource in your tests to compare the actual output. However this approach is very fragile.. in that any substantial change to the report generation code might render all previous Golden Files incorrect. So they would have to be regenerated. If the cost to benefit ratio of automation is too high, I'd say Go manual with old-school word doc test plans.

这篇关于“单元测试"一份报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆