SteveGilham / altcover

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

Error Could not find a part of the path `coverage.xml.acv` #182

Closed marlonbraga closed 1 year ago

marlonbraga commented 1 year ago

Hello,

I have got some errors when try use AltCover in Github Actions. This project in NET framework 4.8

I tried run tests that way:

It thwon a error

ERROR *** Collection phase failed

Could not find a part of the path 'C:\projetos\sonarqube-csharp-test\ConsoleApp.Test\coverage.xml.acv'.

Any idea about why this behaviour is so diferent from running in local environment? How should I use AltCover in Github Actions?

That is the YML used on github actions and the output

Github action workflow

jobs:
  build:
    name: Build
    runs-on: windows-2022
    steps:
    - uses: actions/checkout@v3

    - name: ⚙️Setup MSBuild
      uses: microsoft/setup-msbuild@v1

    - name: ⚙️Setup NuGet
      uses: nuget/setup-nuget@v1

    - name: 📦Restore Packages
      run: nuget restore ConsoleApp.sln

    - name: 🏗️Build Solution
      run: msbuild.exe ConsoleApp.sln

    - name: 🧪Test and Coverage AltCover
      run: ./packages/altcover.8.6.45/tools/net472/AltCover.exe Runner -x='packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe' -r='ConsoleApp.Test/__Instrumented' -t=9 -w . --summary=O -- "ConsoleApp.Test/bin/__Instrumented/ConsoleApp.Test.dll"

The return was:

Run ./packages/altcover.8.[6](https://github.com/turimmfo/sonarqube-csharp-test/actions/runs/4607436209/jobs/8141957544#step:10:6).45/tools/net4[7](https://github.com/turimmfo/sonarqube-csharp-test/actions/runs/4607436209/jobs/8141957544#step:10:8)2/AltCover.exe Runner -x='packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe' -r='ConsoleApp.Test/__Instrumented' -t=[9](https://github.com/turimmfo/sonarqube-csharp-test/actions/runs/4607436209/jobs/8141957544#step:10:10) -w . --summary=O -- "ConsoleApp.Test/bin/__Instrumented/ConsoleApp.Test.dll"

ERROR *** Collection phase failed

Could not find a part of the path 'C:\projetos\sonarqube-csharp-test\ConsoleApp.Test\coverage.xml.acv'.

Details written to D:\a\sonarqube-csharp-test\sonarqube-csharp-test\__Instrumented\AltCover-2023-04-04--[12](https://github.com/turimmfo/sonarqube-csharp-test/actions/runs/4607436209/jobs/8141957544#step:10:13)-02-34.log
Error: Process completed with exit code 1.
SteveGilham commented 1 year ago

I see the problem. The use of runner assumes that the code under test has already been instrumented for coverage.

What you are aiming for is what I termed "Instrument now, test later" in the Modes of Operation wiki page. That mode allows you the extra post-processing options exposed through the runner (or "collect") stage.

Done raw in GitHub actions that would look like

- name: 🚧Prepare with AltCover
      run: ./packages/altcover.8.6.45/tools/net472/AltCover.exe -i ConsoleApp.Test/bin

- name: 🧪Test and Coverage AltCover
      run: ./packages/altcover.8.6.45/tools/net472/AltCover.exe Runner -x='packages/xunit.runner.console.2.4.2/tools/net472/xunit.console.exe' -r='ConsoleApp.Test/bin/__Instrumented' -t=9 -w . --summary=O -- "ConsoleApp.Test/bin/__Instrumented/ConsoleApp.Test.dll"

where the 🚧 stage will probably want to add some filter parameters e.g. to exclude xunit assemblies from the coverage collection.