Mohamed Ramadan
Mohamed Ramadan

Reputation: 485

Unit tests for Apache FOP 1.0

I am using Apache FOP 1.0 to generate PDF files. I want to know to do unit tests for the resulted PDF files and best practices related to it.

Upvotes: 2

Views: 566

Answers (1)

Jeremias Märki
Jeremias Märki

Reputation: 1757

I'm not aware of any tooling that would facilitate the unit testing of PDF. You could convert it to a bitmap (ex. with Apache PDFBox) and compare those to reference bitmaps but that is likely too fragile.

One idea could be to generate an XML format from the PDF objects and compare that using XMLUnit. That would actually make a nice contribution to the Apache PDFBox project IMO. Directly writing Java code using PDFBox to inspect the PDF structure is not very comfortable.

Another possibility is to do what Apache FOP does internally for unit testing the layout engine: Render to one of the two XML-based intermediate formats which represent the formatted pages. Obviously, that won't test the PDF output itself but I suspect you actually want to unit test the generated documents (i.e. your stylesheets), not necessarily the actual PDF because you could rely on Apache FOP to render the intermediate format correctly to PDF.

Upvotes: 3

Related Questions