2

I am trying to run code coverage with Xunit and Fluent Assertions on ASP.NET Core. However, I am getting an error message which I don't really understand.

My project.json of the test project:

{
  "version": "1.0.0-*",
  "testRunner": "xunit",
  "debugType": "portable",
  "dependencies": {
    "xunit": "2.2.0-beta2-build3300",
    "FluentAssertions": "4.15.0",
    "dotnet-test-xunit": "2.2.0-preview2-build1029",
    "ExpenseReporting": "1.0.0-*",
    "Moq": "4.6.38-alpha"
  },
  "commands": {
    "test": "xunit.runner.dnx"
  },
  "frameworks": {
    "netcoreapp1.0": {
      "dependencies": {
        "Microsoft.NETCore.App": {
          "type": "platform",
          "version": "1.0.1"
        }
      }
    }
  }
}

My command for OpenCover:

OpenCover.Console.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"test "C:\Users\johndoe\Desktop\Application\ExpenseReporting.Test\project.json"" -output:coverage.xml -register:user -filter:"+[*]* -[xunit*]* -[*]*Migrations.*"

I receive a lot of errors, but all are of this kind:

An System.IO.DirectoryNotFoundException occured: Could not find a part of the path 'C:\projects\fluentassertions-vf06b\Src\FluentAssertions.NET40\Execution\MSTestFramwork.cs'.

It is clear to me that the directory is not found because it doesn't exist. I am wondering why it tries to access it there?

Stefan
  • 1,590
  • 3
  • 18
  • 33

2 Answers2

2

It looks like OpenCover is trying to include FluentAssertions' source code in its coverage reports. I am not entirely sure why it is doing this but I was able to work around this by telling OpenCover to exclude FluentAssertions.

This is the filter I'm using:

-filter:"+[*]* -[*FluentAssertions*]*"
  • Interesting, but adding filters at least prevents the error messages from showing up. For Reference and use of multiple filters: https://github.com/opencover/opencover/wiki/Usage#understanding-filters – ICantSeeSharp Nov 16 '17 at 08:36
0

Looks like some problem with your project.json file. If you're using dotnet command, there is no commands element. Your project.json file should be something like this.

{
    "version": "1.0.0-*",
    "testRunner": "xunit",
    "dependencies": {
        "xunit": "2.2.0-beta2-build3300",
        "dotnet-test-xunit": "2.2.0-preview2-build1029",
        "FluentAssertions": "4.15.0",
        "ExpenseReporting": "1.0.0-*",
        "Moq": "4.6.38-alpha"
    },
    "frameworks": {
        "netcoreapp1.0": {
            "dependencies": {
                "Microsoft.NETCore.App": {
                    "type": "platform",
                    "version": "1.0.0"
                }
            }
        }
    }
}

https://xunit.github.io/docs/getting-started-dotnet-core.html

Here is the command, which runs test and gets code coverage using open cover.

OpenCover.Console.exe -target:"C:\Program Files\dotnet\dotnet.exe" -targetargs:"test C:\projects\HelloWorld.Tests" -register:user -filter:"+[*]* -[xunit*]*" -output:coverage.xml -oldStyle

Jamie Counsell
  • 7,730
  • 6
  • 46
  • 81
Anuraj
  • 18,859
  • 7
  • 53
  • 79