How to do code coverage for ASP.net application from command prompt
-
2011年10月25日 15:24
Hi
Can anyone tell me steps on how to do code coverage for ASP.NET from command line?
Regards
singhhome
全部回复
-
2011年10月26日 9:50版主
You can use this document and this command: http://msdn.microsoft.com/en-us/library/dd299398(v=vs.90).aspx
Vsinstr -coverage <myprojectbinary>
And if you want to collect the code coverage data, then use this command:
Start vsperfmon -coverage -output:mytestrun.coverage
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
2011年10月26日 14:49
Thanks for reply, i tried it but when i open coverage file it has no results "empty results generated none of the instrmented binaries was used".
after i start vsperfmon, if i do veperfcmd -status, it does not list w3wp.exe as being attached.
i also tried vsperfcmd /start:coverage /cs /user:everyone, but still generated coverage file does not conatin any data, it's 84KB file but no results.
as mentioned at http://msdn.microsoft.com/en-us/vstudio/aa718858.aspx, i could not find on Microsoft.VisualStudio.Coverage.Monitor.dll my machine.
I tried same commands for console application. after starting coverage, vsperfcmd -status does show my exe as being collected. But when i shutdown collector, the coverage file is again 84KB and doesn't show any covered details. It says "empty resutls was generated none of the instrumented binaries were used". It logs below event details in event log
Log Name: Application
Source: VSPERF
Date: 10/26/2011 8:59:21 PM
Event ID: 1406
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Computer:
Description:
There was an error connecting to the Logger Engine while registering MyCustomCollection.exe for coverage.Regards
singhhome
- 已编辑 singhhome 2011年10月26日 15:31
-
2011年10月27日 8:26版主
I think you can try the cross session option: http://social.msdn.microsoft.com/Forums/en/vstsprofiler/thread/e22be7e5-eb12-46e2-a4df-f13e79ed05d7
Can you please try updating your step 6 to include /cs, as follows:
6 vsperfcmd /start:coverage /output:C:\CodeCoverage.coverage /user:"Network Service" /cs
This enables the 'Cross Session' mode for our monitor.
When you run this on remote machines do you connect to those machines via Remote Desktop? Most likely you end up in Session 1 or greater, whereas w3wp.exe runs in session 0. On your local machine (for Win2K3) you are likely in the 'console' session (0) which is the same as w3wp.exe.
If you do happen to be in a different session compared to the process that you are attempting to profile, /cs is required.
Or reset IIS option like this: http://social.msdn.microsoft.com/forums/en-US/vststest/thread/5acee277-c1f1-41c0-96ec-eddf302e4c2e
The following is the updated process for doing code coverage on web services.
1. Read our team blog on code coverage here, especially scenario 3. Please note the path to vsinstr and vsperfcmd is %vsinstalldir%\Team Tools\Performance tools
2. Build your product and test binaries.
3. Instrument your product binaries using vsinstr as detailed in the blog
4. Reset iis.
5. Start the code coverage collection using vsperfcmd /start… as detailed in the blog
6. Open a VS commandline and go to your binary drop location, eg. dd\tcm_1\binaries\x86dbg\bin\i386, run tests using mstest
mstest /testcontainer:ActivitiesTests.dll and mstest /testcontainer:ActivityRuntimeTests.dll
7. Reset iis.
8. Stop the code coverage collection using vsperfcmd /shutdown
9. Open the .coverage file that you get in IDE, check the numbers.
Mike [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
2011年10月27日 14:20
Thanks for reply.
As i had mentioned in my post, i have tried /cs option but still no coverage data, and i am getting event log error while doing coverage for .net console application. Presently i am not trying with ASP.NET.
Thanks
singhhome -
2011年10月28日 10:09版主
Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\PrivateAssemblies\DataCollectors\x86
You can try to find the Microsoft.VisualStudio.Coverage.Monitor.dll in this folder.
Is there any error message box like things popup when you execute that command in your Command Line, if there is, can you show me the screenshot?
Maybe you can have a read this discussion, the post form Chirs.
I will go on research this issue, and if there's any concern, please feel free to let me know.
Best wishes,
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
2011年10月28日 17:34
I tried the programmatic approach.
after
Monitor m = new Monitor(); m.StartRunCoverage(myrunguid, "mytestrun.coverage");
when i launch my exe, an error event is generated in event log as
Log Name: Application
Source: VSPERF
Date: 10/28/2011 11:03:16 PM
Event ID: 1306
Task Category: None
Level: Error
Keywords: Classic
User: N/A
Description:
Profile Monitor does not appear to be running.
singhhome -
2011年10月29日 15:07版主
Have you keep the Process.WaitForExit statement is the code?
Maybe you need to add the /cs argument in the code, instead of just use the original code from that post.
http://social.msdn.microsoft.com/Forums/en/vstsprofiler/thread/2ded76da-3f18-4beb-8248-ec8963ec924f
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
2011年11月2日 8:20版主I am writing to check the status of the issue on your side.What about this problem now?Would you mind letting us know the result of the suggestions?
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

-
2011年11月3日 18:09
i am still not able to get coverage even after using /cs option. Not sure how to troubleshoot it.
singhhome -
2011年11月5日 3:15版主
Analysis->Profiler
Can you use the New Performance Session, then config it through the Performance Explorer, and use this session to profiler your project?
Or can you use the Attach/Detach to attach your process to profile?
Mike Zhang[MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.


