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

Token Expansion Doesn't Work When Running Tests at Solution Level #77

Open
rcollette opened this issue Apr 1, 2024 · 2 comments
Open

Comments

@rcollette
Copy link

rcollette commented Apr 1, 2024

I'm running tests on an entire solution, as documented here:
https://devblogs.microsoft.com/dotnet/whats-new-in-our-code-coverage-tooling/

My command line looks like:

dotnet test --settings CodeCoverage.runsettings --collect "Code Coverage;Format=cobertura" --logger:"junit;LogFilePath=..\reports\unit-tests\;LogFileName={assembly}.test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose" --results-directory ./TestResults

I have also tried

dotnet test --settings CodeCoverage.runsettings --collect "Code Coverage;Format=cobertura" --logger:"junit;LogFilePath=..\reports\unit-tests\{assembly}.test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose" --results-directory ./TestResults

My CodeCoverage.runsettings file looks like:

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
  <DataCollectionRunSettings>
    <DataCollectors>
      <DataCollector friendlyName="Code Coverage" uri="datacollector://Microsoft/CodeCoverage/2.0" assemblyQualifiedName="Microsoft.VisualStudio.Coverage.DynamicCoverageDataCollector, Microsoft.VisualStudio.TraceCollector, Version=11.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
        <Configuration>
          <Format>cobertura</Format>
          <IncludeTestAssembly>false</IncludeTestAssembly>
          <CodeCoverage>  
            <EnableStaticNativeInstrumentation>False</EnableStaticNativeInstrumentation>
            <EnableDynamicNativeInstrumentation>False</EnableDynamicNativeInstrumentation>
            <ModulePaths>
              <Include>
                <ModulePath>Precisely.Identity.*</ModulePath>
              </Include>
            </ModulePaths>
            <Attributes>
              <Exclude>
                <!-- Don't forget "Attribute" at the end of the name -->
                <Attribute>^System\.Diagnostics\.DebuggerHiddenAttribute$</Attribute>
                <Attribute>^System\.Diagnostics\.DebuggerNonUserCodeAttribute$</Attribute>
                <Attribute>^System\.CodeDom\.Compiler\.GeneratedCodeAttribute$</Attribute>
                <Attribute>^System\.Diagnostics\.CodeAnalysis\.ExcludeFromCodeCoverageAttribute$</Attribute>
              </Exclude>
            </Attributes>
            <Sources>
              <Exclude>
                <Source>.*\\*.g.cs</Source>
                <Source>\\_\\.*</Source>
              </Exclude>
            </Sources>
          </CodeCoverage>
        </Configuration>
      </DataCollector>
    </DataCollectors>
  </DataCollectionRunSettings>
</RunSettings>

I just get a single unit test output file

image

@codito
Copy link
Contributor

codito commented Jun 22, 2024

Unable to repro with this project: https://gitlab.com/codito/sample-junit-test

> dotnet test --settings test.runsettings --collect "Code Coverage;Format=cobertura" --logger:"junit;LogFileName={assembly}.test-result.xml;MethodFormat=Class;FailureBodyFormat=Verbose" --results-directory ./TestResults

  Determining projects to restore...
  All projects are up-to-date for restore.
  TestProject -> /home/arun/src/spekt/sample-junit-test/TestProject/bin/Debug/net8.0/TestProject.dll
  TestProject.Tests -> /home/arun/src/spekt/sample-junit-test/TestProject.Tests/bin/Debug/net8.0/TestProject.Tests.dll
Test run for /home/arun/src/spekt/sample-junit-test/TestProject.Tests/bin/Debug/net8.0/TestProject.Tests.dll (.NETCoreApp,Version=v8.0)
Microsoft (R) Test Execution Command Line Tool Version 17.8.0 (x64)
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Results File: /home/arun/src/spekt/sample-junit-test/TestResults/TestProject.Tests.test-result.xml

Passed!  - Failed:     0, Passed:     1, Skipped:     0, Total:     1, Duration: 25 ms - TestProject.Tests.dll (net8.0)

Attachments:
  /home/arun/src/spekt/sample-junit-test/TestResults/a780d188-d1c1-4b3d-96f4-09caf294e86d/637bc222-49b5-49d8-92c0-2acba997a6e4.cobertura.xml

@stubbfel
Copy link

I had the same issue and after a while i just realized that I referenced the wrong package.

<PackageReference Include="JUnitTestLogger" Version="1.1.0" />

This package https://www.nuget.org/packages/JUnitTestLogger did not support token/macro expansion ( syncromatics/JUnitTestLogger#2 )

But with the correct one (from this repo) it is working :

<PackageReference Include="JunitXml.TestLogger" Version="4.1.0" />

@rcollette I hope the share of my fault can help you

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

3 participants