The Code Coverage Report

I had someone that told me recently that they needed to find a way to get code coverage in T-SQL. Not for them, not to improve quality, but because their manager wanted a report.

OK, here it is.

First, build a nice SSRS report that displays your company logo, a header, the current date, and a pie chart. Yes, I know pie charts are bad, but they’re good for managers that want something like code coverage.

Now, for the data source of the report, here’s your query:

SELECT 90 + ((RAND() * 8)-2)

Now, you won’t always get over 90%, which is what some people want, but you’ll get over 90 eventually.

About way0utwest

Editor, SQLServerCentral
This entry was posted in Blog and tagged , , . Bookmark the permalink.

5 Responses to The Code Coverage Report

  1. Pingback: Don’t Use Code Coverage | Voice of the DBA

  2. Michael says:

    Thanks I’ve been looking for a solution to this……my manager will really like the pie chart….might add a couple of colourful swirly things as well.

  3. Tom Thomson says:

    ideally there should be a way of getting the code coverage to decrease when extra last-minute requirements are sneaked in by management; then when the manager asks why the code coverage has deteriorated you can tell him that (a) you can’t have coverage of code that’s not yet written and (b) these crazy new requirements change everything so much and introduce so many new paths through the modified version of existing code that a whole new test suite will have to be built before the coverage gets back anywhere near where it was before even for the existing code. With luck that will either get the crazy new requirements withdrawn; or maybe it will lead to your taking up a new job.

Comments are closed.