Skip to content

Coverlet fails with "Index was out of range" when assembly under test has no public methods #230

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

Closed
andrewtyped opened this issue Oct 27, 2018 · 4 comments
Labels
bug Something isn't working

Comments

@andrewtyped
Copy link

This is related to @csharpsi 's and @vikasillumina 's comments in #179 . Coverlet fails with the index out of range error when the assembly under test (not the test assembly itself) has no public methods. Adding a single public method to the assembly under test allows coverlet's report generation to succeed.

I have a minimal repository at https://github.com/andrewtyped/Coverlet.EmptyProjectIssue which demonstrates the issue - just run the build.ps1 script to see the error during the Task_Test_My_Test_Project_net461 step. This runs a Cake script which in turn runs dotnet test against the My.Test.Project.Test project. Sample output:

========================================
Task_Test_My_Test_Project_net461
========================================

Test run for C:\dev\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Release\net461\My.Test.Project.Test.dll(.NETFramework,Version=v4.6.1)
Microsoft (R) Test Execution Command Line Tool Version 15.8.0
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
No test is available in C:\dev\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Release\net461\My.Test.Project.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example  /TestAdapterPath:<pathToCustomAdapters>.

Calculating coverage result...
  Generating report '.\TestResults\My.Test.Project.net461\coverage.cobertura.xml'
C:\Users\.nuget\coverlet.msbuild\2.1.1\build\netstandard2.0\coverlet.msbuild.targets(23,5): error : Index was out of range. Must be non-negative and less than the size of the collection. [C:\dev\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\My.Test.Project.Test.csproj]
C:\Users\.nuget\coverlet.msbuild\2.1.1\build\netstandard2.0\coverlet.msbuild.targets(23,5): error : Parameter name: index [C:\dev\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\My.Test.Project.Test.csproj]
An error occurred when executing task 'Task_Test_My_Test_Project_net461'.
Error: One or more errors occurred.
        .NET Core CLI: Process returned an error (exit code 1).
@tonerdo tonerdo added the bug Something isn't working label Nov 4, 2018
@richardacre
Copy link

We encountered a similar situation, but this time the test project itself contained a class that had no public methods in it. Adding a simple public property getter-setter fixed it.

@MarcoRossignoli
Copy link
Collaborator

@andrewtyped I cannot repro, can you help me to understand what I'm missing?

D:\git\Coverlet.EmptyProjectIssue (master -> origin)
λ powershell .\build.ps1
Preparing to run build script...
Cake
ReportGenerator
packages.config
packages.config.md5sum
Running build script...

========================================
Task_Restore_My_Test_Project
========================================
An error occurred when executing task 'Task_Restore_My_Test_Project'.
Error: One or more errors occurred.
        MSBuild: Could not locate executable.

D:\git\Coverlet.EmptyProjectIssue (master -> origin)
λ dotnet test /p:CollectCoverage=true
Test run for D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\net461\My.Test.Project.Test.dll(.NETFramework,Version=v4.6.1)
Microsoft (R) Test Execution Command Line Tool Version 16.0.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
No test is available in D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\net461\My.Test.Project.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example  /TestAdapterPath:<pathToCustomAdapters>.

Calculating coverage result...
  Generating report 'D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\coverage.json'

+-----------------+--------+--------+--------+
| Module          | Line   | Branch | Method |
+-----------------+--------+--------+--------+
| My.Test.Project | 0%     | 0%     | 0%     |
+-----------------+--------+--------+--------+

Test run for D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\netcoreapp2.0\My.Test.Project.Test.dll(.NETCoreApp,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 16.0.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
No test is available in D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\netcoreapp2.0\My.Test.Project.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example  /TestAdapterPath:<pathToCustomAdapters>.

Calculating coverage result...
  Generating report 'D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\coverage.json'

+-----------------+--------+--------+--------+
| Module          | Line   | Branch | Method |
+-----------------+--------+--------+--------+
| My.Test.Project | 0%     | 0%     | 0%     |
+-----------------+--------+--------+--------+


D:\git\Coverlet.EmptyProjectIssue (master -> origin)
λ

@MarcoRossignoli
Copy link
Collaborator

Never mind...found it, I missed cobertura format.

@MarcoRossignoli
Copy link
Collaborator

Close because fixed with newer version...works with 2.6.2

D:\git\Coverlet.EmptyProjectIssue (master -> origin)
λ dotnet test /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura
Test run for D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\net461\My.Test.Project.Test.dll(.NETFramework,Version=v4.6.1)
Microsoft (R) Test Execution Command Line Tool Version 16.0.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
No test is available in D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\net461\My.Test.Project.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example  /TestAdapterPath:<pathToCustomAdapters>.

Calculating coverage result...
  Generating report 'D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\coverage.cobertura.xml'

+-----------------+------+--------+--------+
| Module          | Line | Branch | Method |
+-----------------+------+--------+--------+
| My.Test.Project | 100% | 100%   | 100%   |
+-----------------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | 100% | 100%   | 100%   |
+---------+------+--------+--------+

Test run for D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\netcoreapp2.0\My.Test.Project.Test.dll(.NETCoreApp,Version=v2.0)
Microsoft (R) Test Execution Command Line Tool Version 16.0.1
Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait...
No test is available in D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\bin\Debug\netcoreapp2.0\My.Test.Project.Test.dll. Make sure that test discoverer & executors are registered and platform & framework version settings are appropriate and try again.

Additionally, path to test adapters can be specified using /TestAdapterPath command. Example  /TestAdapterPath:<pathToCustomAdapters>.

Calculating coverage result...
  Generating report 'D:\git\Coverlet.EmptyProjectIssue\test\My.Test.Project.Test\coverage.cobertura.xml'

+-----------------+------+--------+--------+
| Module          | Line | Branch | Method |
+-----------------+------+--------+--------+
| My.Test.Project | 100% | 100%   | 100%   |
+-----------------+------+--------+--------+

+---------+------+--------+--------+
|         | Line | Branch | Method |
+---------+------+--------+--------+
| Total   | 100% | 100%   | 100%   |
+---------+------+--------+--------+
| Average | 100% | 100%   | 100%   |
+---------+------+--------+--------+


D:\git\Coverlet.EmptyProjectIssue (master -> origin)
λ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants