Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Class names are not reported to Code Coverage #2623

Open
3 tasks done
powercode opened this issue Feb 23, 2025 · 0 comments
Open
3 tasks done

Class names are not reported to Code Coverage #2623

powercode opened this issue Feb 23, 2025 · 0 comments

Comments

@powercode
Copy link
Contributor

powercode commented Feb 23, 2025

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant