Using .runsettings to exclude assemblies from code coverage

前端 未结 5 989
孤城傲影
孤城傲影 2020-12-09 03:40

When running code coverage for my solution which contains multiple projects, I noticed that Code Coverage includes also my test assemblies.

I found an article which

5条回答
  •  半阙折子戏
    2020-12-09 04:11

    As I couldn't find this answer anywhere else, and this just took me a while to figure out, ModulePath is the full path, and you may be matching your pattern somewhere else in the path.

    For example, if you have a project Foo and a project Foo.Tests, and they are built to their own directories, you will end up with Foo.Tests\bin\Release\Foo.dll and Foo.Tests\bin\Release\Foo.Tests.dll. This is the dll that the test assembly will reference, so this is the path that is used. Foo\bin\Release\Foo.dll is not directly referenced by the test assembly.

    If you try to exclude .*tests.* it will match both paths and produce no coverage.

    To only exclude assemblies with "test" in their file name, ignoring their path, I used

    
      .*\\[^\\]*test[^\\]*\.dll
    
    

提交回复
热议问题