Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Measuring code coverage in Delphi

Tags:

Is there any way to measure code coverage with DUnit? Or are there any free tools accomplishing that? What do you use for that? What code coverage do you usually go for?

Jim McKeeth: Thanks for the detailed answer. I am talking about unit testing in the sense of a TDD approach, not only about unit tests after a failure occured. I'm interested in the code coverage I can achieve with some basic prewritten unit tests.

like image 233
jpfollenius Avatar asked Feb 10 '09 08:02

jpfollenius


People also ask

How do you measure code coverage?

To calculate the code coverage percentage, simply use the following formula: Code Coverage Percentage = (Number of lines of code executed by a testing algorithm/Total number of lines of code in a system component) * 100.

What tool is used to measure code coverage?

Code coverage tools are available for many programming languages and as part of many popular QA tools. They are integrated with build tools like Ant, Maven, and Gradle, with CI tools like Jenkins, project management tools like Jira, and a host of other tools that make up the software development toolset.

How do you use code coverage analysis?

Code Coverage Analysis is the process of discovering code within a program that is not being exercised by test cases. This information can then be used to improve the test suite, either by adding tests or modifying existing tests to increase coverage.


2 Answers

I have just created a new open source project on Google Code with a basic code coverage tool for Delphi 2010. https://sourceforge.net/projects/delphicodecoverage/

Right now it can measure line coverage but I'm planning to add class and method coverage too.

It generates html reports with a summary as well as marked up source showing you what lines are covered (green), which were not (red) and the rest of the lines that didn't have any code generated for them.

Update: As of version 0.3 of Delphi Code Coverage you can generate XML reports compatible with the Hudson EMMA plugin to display code coverage trends within Hudson.

Update: Version 0.5 brings bug fixes, increased configurability and cleaned up reports

Update: Version 1.0 brings support for emma output, coverage of classes and methods and coverage of DLLs and BPLs

like image 199
Christer Fahlgren Avatar answered Nov 08 '22 09:11

Christer Fahlgren


I don't know of any free tools. AQTime is almost the defacto standard for profiling Delphi. I haven't used it, but a quick search found Discover for Delphi, which is now open source, but just does code coverage.

Either of these tools should give you an idea of how much code coverage your unit tests are getting.

like image 35
Bruce McGee Avatar answered Nov 08 '22 07:11

Bruce McGee