The Methodology of Generating Reports Programmatically

Just recently I began working as a developer creating custom reports for customers. These reports can be in any number of formats: csv, Excel 98, Excel 2007, PDF, and a number of other proprietary binary formats.

Sadly, looking into the code base as it currently exists did not reveal any secrets or surprises about proper abstraction and encapsulation for report creation, and searching online mainly revealed questions about how to export into various formats or offers of businesses providing reporting solutions.

This lead to a big question: what is the best methodology for creating reports programmatically?

Based on the current code base and my searching, the solution seemed to be as follows:

public ReportType CreateReport()
    var report = new ReportType();
    return report;

This, however, leads to a whole pile of concerns. Where is the abstraction? How do you unit test a report?

This lead me to an idea: the data should be completely encapsulated from the report styling and export format.

This is very similar to the MVC (Model-View-Controller) pattern. In essence, the data, the logic, and the styling are completely separate pieces of the report. This allows you the freedom of creating a data model that will work for the custom report being created and then passing that completed model to your test cases. Report styling can be tested with visual acceptance tests.

Not only does this separation of concerns allow you to actually test report creation, but it will also narrow down exactly where any bugs are occurring. If the styling is off, then it’s an issue with the styling code. If the data is incorrect, check the logic. If the model is not sufficient for the data then you need to go back and adjust the schema being used.

In the future, I will drill into this further and discuss with examples where the sticking points are and exactly how something like this might be implemented.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s