Crystal Reports and TDD

It is my experience that doing TDD (test driven development) could help avoid some pain with Crystal Reports. Suppose that you have a column of floating point numbers that go out to 6 places. You want to display those numbers to the user rounded to 2 places. Then you are going to display the sum of the numbers displayed. This is where the fun comes in. It was our experience that the sum being displayed is the sum of the unrounded numbers that was then rounded to 2 places. This is entirely different than rounding first and then summing.

So what is the answer? The answer is in the pink book. TDD of the presentation layer is tough. Keep the presentation layer thin. TDD the business logic that puts together the numbers that will be displayed, include the rounding and summing. Pass a dataset or multiple datasets with the data to your Crystal Report. Now your presentation layer is thin and doesn't have to know anything about where the data came from. (No redirecting of databases at run time!)