1

I am covering my project with unit tests, and there are some lines which obviously will never be reached. E.g.:

constructor TSomeClass.Create;
begin
    inherited Create;
    raise ENotSupportedException.Create('This class does not support parameterless Create') at ReturnAddress;
end;//<- this line generates code but is unreachable

To measure coverage I am using Delphi-code-coverage

As far as I googled, and browsed its code I found no way to mark this end; as one which cannot be covered.

So, is there any way to mark such lines?

Serhii Kheilyk
  • 933
  • 1
  • 8
  • 24
  • Just a link to a delphi code-coverage answer here at SO: [Measuring code coverage in Delphi](https://stackoverflow.com/a/3115701/576719) – LU RD Oct 04 '17 at 12:00
  • @LURD: I didn't catch what is your comment about. My question is about the usage of the tool, already selected, not about which tool should I select. – Serhii Kheilyk Oct 04 '17 at 12:14
  • Yes I know, I just provided a cross-reference link. – LU RD Oct 04 '17 at 12:18
  • 1
    Just a stupid idea - Assuming that the "Delphi Code Coverage" tool uses the blue breakpoint lines, your `Error(..)` method could be non-public and marked with the `inline` directive. That effectively removes the blue breakpoints. – Günther the Beautiful Oct 04 '17 at 17:22
  • 1
    Or you could redesign the code so that the `Error` method returns the exception rather than raising it directly. Not always what you want though. – Honza R Oct 05 '17 at 06:18
  • @HonzaR: Well, real code is in the constructor (I have updated the question), so returning the exception is not an option. – Serhii Kheilyk Oct 05 '17 at 06:31
  • @GünthertheBeautiful: Well, real code is in the constructor (I have updated the question), so I cannot make it neither `inline` nor `private` – Serhii Kheilyk Oct 05 '17 at 06:35
  • 1
    In that case, I would throw a `System.SysUtils.ENoConstructException` which seems to be made for stuff like this. Not answering the question, but still wanted to mention it. – Günther the Beautiful Oct 05 '17 at 08:41
  • 1
    See [How to hide the inherited TObject constructor while the class has overloaded ones?](https://stackoverflow.com/q/14003153/576719). There are solutions that will make the `TSomeClass.Create` obsolete. – LU RD Oct 05 '17 at 11:27

0 Answers0