Skip to content

Class names are not reported to Code Coverage #2623

Open
@powercode

Description

@powercode

Checklist

What is the issue?

Methods in classes are displayed in code coverage as just the method's name.

Having ClassName.MethodName would make the code coverage report much easier to navigate.

I read the previous issues about classes and code coverage but didn't understand the problem.
Is there some technical reason why we throw away the name of the class?

For example, in cobertura, we have this XML, where the filename has replaced the class.

The ToString() method is part of a Person class, and also part of an Employee class but this is information is lost.

...
<classes>
  <class name="cc.psm1" filename="cc.psm1" line-rate="1" branch-rate="1">
    <methods>
      <method name="ToString" signature="()">
        <lines>
          <line number="3" hits="1" />
          <line number="7" hits="1" />
        </lines>
      </method>
    </methods>
    <lines>
      <line number="3" hits="1" />
      <line number="7" hits="1" />
    </lines>
  </class>
</classes>
...

Expected Behavior

I would have expected to see Person.ToString() as the method name instead of ToString()

That way, I can tell it apart from Employee.ToString() later in the same file.

Steps To Reproduce

# cc.psm1
class Person {
   [string] ToString() { return "A Person" }
}

class Employee {
   [string] ToString() { return "An Employee" }
}
Describe cc {
    import-module -Name $PSSCriptRoot\cc.psm1
    Context mod {
        InModuleScope cc {
            It 'Should have a Person.ToString() method' {
                [Person]::new().ToString() | Should -Be 'A Person'
            }

            It 'Should have an Employee.ToString() method' {
                [Employee]::new().ToString() | Should -Be 'An Employee'
            }
        }
    }
}
# run_tests.ps1

$config = New-PesterConfiguration
$config.CodeCoverage.Enabled = $true
$config.CodeCoverage.Path = 'cc.psm1'
$config.CodeCoverage.OutputFormat = 'Cobertura'
$config.Run.Path = "$PSScriptRoot\cc.tests.ps1"
Invoke-Pester -Configuration:$config

Describe your environment

Pester 5.7.1

Name                           Value
----                           -----
PSVersion                      7.5.0
PSEdition                      Core
GitCommitId                    7.5.0
OS                             Microsoft Windows 10.0.26100
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Possible Solution?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions