How can I test a jasper report?

user297339 picture user297339 · Aug 4, 2010 · Viewed 12.5k times · Source

I want to test all the jasper reports of my application. I want to be able to detect:

  • Compilation problems (Would checking that JasperCompileManager.compileReport(some inputStream) doesn´t throw JRException is a good option for this?)
  • Filling problems (Would checking that JasperFillManager.fillReport(someReport, someParameters, someDataSource) doesn´t throw JRException is a good option for this?)
  • Rendering problems: detect "null" strings appearing, text looking truncated in the exported PDF file
  • Any other idea?

Ideally I would like to keep the testing process the most generic possible. The thing is that each jasper has a different data source so for detecting this errors i need to generate at list some data (right?) and this data I need to generate is different for each jasper of my application. So i don´t know how much testing code I would be able to reuse. What approach would you take?

Thanks!

Answer

garfiny picture garfiny · Apr 19, 2011

I created a couple of unit test for testing aspects.

  1. Compilation problems: I created a class to load and compile all of my templates. My enviornment is web-based. So I tested the path through this as well.

  2. For filling: I mocked data and JRDataSource to fill a template, that works find for me.

  3. For Rendering: I haven't found a good approach to do it. Anyone got ideas?

And also, I usually use JavaBean data source so that I can test the reports using a traditional java unit test method.