Skip to content

Behavior changes between MTP and Legacy (msbuild) #1878

@james-newell-forge

Description

@james-newell-forge

Hi Team,

I first want to say thank you for making this tool and continuing to upgrade it to the MTP test runner.

I was exploring moving our project to MTP while upgrading to dotnet 10.0 and one thing I noticed was that I was getting different coverage results between using legacy and MTP. I (really Claude AI) managed to track it down to a few behavior changes between the two and was wondering if we could have a discussion about giving the option to restore the original behavior.

SkipAutoProps is true by default

So, in legacy SkipAutoProps is false by default. This wouldn't be a big deal but you actually can't set this option to false using the option --coverlet-skip-auto-props. The following code fragment shows the bug: if you don't set it, the value is true by default but if you do set it, it is also true.

CoverageConfiguration.cs

public bool SkipAutoProps =>
    GetBoolOptionWithDefault(CoverletOptionNames.SkipAutoProps, defaultValue: true);

private bool GetBoolOptionWithDefault(string optionName, bool defaultValue)
{
    bool isSet = _commandLineOptions.IsOptionSet(optionName);
    if (isSet)
    {
        _logger?.LogDebug($"[Explicitly set] {optionName}: true");
        return true;
    }

    _logger?.LogDebug($"[Default] {optionName}: {defaultValue}");
    return defaultValue;
}

Additional default ExcludeByAttributes

In legacy, only the ExcludeFromCodeCoverageAttribute attribute is included by default, but in MTP it includes GeneratedCodeAttribute and CompilerGeneratedAttribute attributes which seems to be added to compiled code automatically by the SDK. This caused coverage discrepencies during testing. There seems to be no way to change the defaults. Maybe we could add an option to exclude defaults as an escape hatch (maybe --coverlet-no-exclude-by-attribute-defaults), or whatever ideas you have.

CoverageConfiguration.cs

private static readonly string[] s_defaultExcludeByAttributes =
[
    "ExcludeFromCodeCoverage",
    "ExcludeFromCodeCoverageAttribute",
    "GeneratedCodeAttribute",
    "CompilerGeneratedAttribute"
];

Timestamp added to coverage file

This one i can definetly see the benefit of having, but can we make it opt-in or some way to disable it via options? For example, we could have an option --coverlet-postfix-timestamp that when set includes the timestamp in the file, otherwise use the default legacy behavior

Metadata

Metadata

Assignees

No one assigned

    Labels

    SolvedThe issue is solved and can be closedbugSomething isn't workingdriver-MTPIssue related to Microsoft Testing Platform driver

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions