SteveGilham / altcover

Cross-platform coverage gathering and processing tool set for dotnet/.Net Framework and Mono
MIT License
498 stars 18 forks source link

How to get coverage for classes with just auto properties #188

Closed sixeyes closed 1 year ago

sixeyes commented 1 year ago

I'm using the AltCover v8.6.61 and I'd like code coverage reports on my model objects (i.e. simple properties only).

I'm testing that the classes serialise / deserialise as I'd expect. The code coverage of these classes would serve to remind me that I'd forgotten to write these tests.

I'm using the following command line

dotnet test /p:AltCover=true /p:AltCoverAttributeFilter=ExcludeFromCodeCoverageAttribute /p:AltCoverLocalSource=true

and I've tried adding /p:AltCoverTrivia=true and /p:AltCoverTrivia=false but neither made any difference.

Is there another setting I could try or is this just not possible?

At the moment the classes are being shown with no coverage and when I click on the class in the Coverage Report I'm told:

No files found. This usually happens if a file isn't covered by a test or the class does not contain any sequence points (e.g. a class that only contains auto properties).

SteveGilham commented 1 year ago

The flag /p:AltCoverTrivia=true omits trivial sequence points (typically lines containing just { or }) which have debug information, but are either no-op or unconditional jump instructions, so are not "interesting" for logic testing.

The flag you are looking for is /p:AltCoverShowStatic=++ ; the static here meaning static analysis (methods with code so simple that its correctness can be validated just by looking at the IL).

Do be aware that, for auto-properties, it is possible for the compiler to inline property calls as a direct access of the compiler generated backing field, so even with this flag set and the property exercised in the source, coverage may still not show.

sixeyes commented 1 year ago

Thanks for getting back to me.

The ShowStatic parameter didn't make any difference, so from what you've said, the code isn't there to be covered.