Skip to content
This repository has been archived by the owner on Nov 15, 2021. It is now read-only.

Support for code coverage for ASP.NET 5 projects. #327

Closed
anuraj opened this issue Jul 20, 2015 · 19 comments
Closed

Support for code coverage for ASP.NET 5 projects. #327

anuraj opened this issue Jul 20, 2015 · 19 comments

Comments

@anuraj
Copy link

anuraj commented Jul 20, 2015

Support for code coverage for ASP.NET 5 projects.

We can run the test in ASP.NET 5 using dnx . test command, where . is the current directory, where we require the project.json file. So I am the command like this.

OpenCover.Console.exe -target:C:\Users\Anuraj.P\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta5\bin\dnx.exe -targetargs:" . test" -output:coverage.xml

coverage

You can find the source code and test project - https://github.com/anuraj/ASPNET5CIDemo

If you want to configure DNX, please check the appveyor.yml or .travis.yml

@sawilde
Copy link
Member

sawilde commented Jul 20, 2015

Thanks, what version of OpenCover are you using? The latest release can be found here https://github.com/OpenCover/opencover/releases if you need it.

In the meantime what does it say in the XML about where it loaded the assembly from and why it didn't instrument it?

@scotroach
Copy link

I too have the same problem.
The projects are the new ASP.NET 5 - XProj.
In the xml says it was skippedDueTo="MissingPdb"

OS.Core.dll
OS.Core

@gBritz
Copy link

gBritz commented Sep 2, 2015

I am also having the same problem, using dnx-clr-win-x86.1.0.0-beta6.
Output file says it was skippedDueTo="MissingPdb" in dlls of project and hash attribute is empty.
Is there another way to inform the path of the pdb file?

@sawilde
Copy link
Member

sawilde commented Sep 3, 2015

-targetdir: may work for you

the original OP did not respond to my query so I have not pushed on the support

@gBritz
Copy link

gBritz commented Sep 3, 2015

Thanks for your suggestion.
I tried to use the -targetdir:, but i had another error.
You can check here
Have you any sample project with dnx to base me?

@sawilde
Copy link
Member

sawilde commented Sep 3, 2015

Have you any sample project with dnx to base me?

Sorry I don't, what you could try is using the full path to the targetdirectory.

@anuraj
Copy link
Author

anuraj commented Sep 3, 2015

It tried the latest version. opencover.4.6.192.msi, XML says skippedDueTo="MissingPdb".

@Cobster
Copy link

Cobster commented Sep 3, 2015

I think I got it figured out. Specify the --lib argument with the dnx command that targets the folder containing the PDB of the assembly being covered.

For instance here is my command:

OpenCover.Console.exe -target:C:\users\jbruun.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta6\bin\dnx.exe -targetargs:"--lib c:\projects\cpip\src\website\bin\debug\dnx451 c:\projects\cpip\te
st\Website.Tests. test" -output:coverage.xml -filter:+[Website]*

@gBritz
Copy link

gBritz commented Sep 3, 2015

@Cobster
Great awesome.
Thanks, your suggestion really works.
Build with coverage here

@anuraj
Copy link
Author

anuraj commented Sep 4, 2015

It is working for me, but the results include XUnit assemblies as well. If I include filter option the report is not getting generated.

@sawilde
Copy link
Member

sawilde commented Sep 4, 2015

@Cobster thanks - I'll add it to the wiki and documentation

@Cobster
Copy link

Cobster commented Sep 4, 2015

@sawilde - Your welcome, glad this could get figured out without requiring new bits.
@anuraj - Does the lib folder you are targeting contain the PDB? I've had to use the dnu build from the command line to get the dll and pdb created, a simple build in visual studio doesn't seem to generate the artifacts.

@anuraj
Copy link
Author

anuraj commented Sep 4, 2015

Yes. I have the DLL and PDB. But I didn't understand why filter option is not working. If I apply filter:"-[XUnit*]*" - It is not generating the report :(

@Cobster
Copy link

Cobster commented Sep 4, 2015

@anuraj - Not sure if its case sensitive, but if it is the XU in XUnit should be lowercase to match the assembly name. Are you adding the asterisk wildcard after [xunit] so it will filter the types?

I've had better luck using the inclusion filter to specify my own assemblies.

@sawilde
Copy link
Member

sawilde commented Sep 4, 2015

@anuraj add +[*]* opencover filters have a default set but when you supply your own then it is exclusive by default this is so we don't bring in coverage for 3rd party assemblies and the runtime, which may skew your results and make it very, very slow.

as @Cobster mentions the inclusive way is much easier and you are much more in control e.g.

-filter:"+[MyCompanyName*]* -[*Tests]*"

which you include all the assemblies beginning with MyCompanyName but exclude any that have Tests at the end.

All of this is in the wiki usage guide

@sawilde
Copy link
Member

sawilde commented Sep 5, 2015

@sgopimca7
Copy link

sgopimca7 commented Sep 7, 2017

When the code reads the value from configuration file such as scenarios like reading connection string from database, then it always throws null exception and all test methods are fail.
I am using the opencover with MSTest Test methods. Actually all test methods works fine in local, but when i run through the opencover, then the test methods which has the code to read configuration from app.config are always fails.

@sawilde
Copy link
Member

sawilde commented Sep 9, 2017

@sgopimca7 Please open a new issue with a repeatable scenario

@abhimanyuk453
Copy link

i am facing similar issue where for my project .net framework 4.6.2 hosted in iis ,i am unable to generate xml file for my project.
Command used is : OpenCover.Console.exe -target:C:\Windows\System32\inetsrv\w3wp.exe -targetargs:-debug -targetdir:C:\inetpub\wwwroot\coverage\bin\ -register:user
could you please help me with this issue. @sawilde
opencoverissue

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants