how to check code coverage of specific controller in mvc? - unit-testing

I want to know the steps for analyzing code coverage of any specific controller.
I am working on ASP.NET MVC4 with Visual Studio 2012 and TFS setup.
I know that with can analyze code coverage of all of the controllers from test explorer window "Analyze code coverage for all controller" option.
But i want to check the code coverage of any one controller.

First you can group them by the Class Name in the Test Explorer window. Then find the specific Controller you need the Code Coverage. Then Right Click on the at Controller, and select "Analyze Code Coverage For Selected Tests". This would produce the Code Coverage for the specific Controller you selected. Note that you see all other Controllers/Types have been instrumented in the Code Coverage Result window, however they don't have any coverage result. It would just say Covered (Blocks) = 0.

Related

IntelliJ Idea - Jump to test code of covered code?

Is there a way to jump to test code that is already in place? for example, let's say I have a method and some of the code is 'covered' after I run with coverage. How would I be able to tell what unit tests are covering this code without manually checking each test?
#jonrsharpe gave me the resources to answer this question, so thanks!
check this out here, it will give you all the information you will need: info on viewing code coverage results
this feature can be accessed by clicking on the coloured line by your code and clicking on a button called 'show tests covering line' this option is only available if you enable 'tracing' for your code coverage. this option can be enabled from configuring the test task. info on this bit here: info on configuring run profiles for code coverage

Intellij Idea How to show tests covering line

I'm using IDEA in order to analyze our code coverage.
I can see that some lines were called N number of times. But I also want to know which test caused that line call.
I see the appropriate button "Show tests covering line", but this button is disabled for all of the lines.
So what is the reason of that behavior and is it possible to force IDEA to show tests which called a particular line of the code
From the docs:
For JUnit tests, you can open the test that covers a line in a separate dialog. To do so, click the the Show Tests Covering Line icon in the popup. To be able to use this feature, enable the Tracing mode and Track per test coverage options for the current run/debug configuration in the Code Coverage area. For more information, refer to Set coverage in run configurations.
The Set Coverage in run configurations page details how to do this for your IDE version. Newer versions will have a Coverage Tab, older versions will not. The set up instructions for both are detailed in this page.

Code coverage results do not match in local visual studio and TFS build server

recently i created unit test methods for my project solution. when i do code analysis to find out code coverage, it shows 82% code coverage.
But when i checked in my code on TFS, on build server code analysis report shows code coverage as 58%.
Please can someone let me know if they encountered this issue or any possible solution?
In the TFS build definition, did you specify a .runsetting file or Test Filter criteria for code coverage analysis or just choose the "CodeCoverageEnabled" setting?
If you set the filter or .runsettings, that should be the reason why the code coverage results are different. Please see below articles for details.
Configure unit tests by using a .runsettings file
Customizing Code Coverage Analysis
So, If you want to do a comparison, you should be under the same conditions. The filter will exclude those test methods which do not meet the criteria. So not all tests are run, and the code coverage result is not same with developers.
You could delete the filter criteria and test again.
More other reasons to cause the difference please see :Troubleshooting Code Coverage

Visual Studio Team Services isn't Displaying Published Unit Tests

We have been using Visual Studio Team Services for about 2 years now with great success. It seems that in recent months something happened to the display of unit test metrics/results. I used to see drill down information for the tests that were published but now that has disappeared. In addition I now see this strange JSON text where unit test information used to be. I've searched high and low for an answer to this and came up empty. Any help would be appreciated.
I can get the same behavior as you when publish the test result via MSTest or VSTest.Console. I have help you submit a feedback on MS Connect Page, you can track it here: Published test result does not show in Build Summary Report.
And for now, you can use the "Publish Test Result" task in vNext build to publish the test result, it can get the test result displayed in build summary.
After switching away from XAML builds to the new build system this problem was resolved. Now a simple Unit test step was added with the appropriate properties setup and it worked like a champ.

TeamCity: How do you report low unit test coverage?

We use TeamCity 7 (upgrade to 8 is possible) for continuous integration and we set ourselves a target of unit test coverage 90%. I know how to fail the build if the coverage is lower, but I'd not like to do so, as a missing test will slow down all the development.
On the other hand, I'd like to have clear visibility on the build overview page that the coverage is low - the only option I see is a service message like this one:
##teamcity[buildStatus status='SUCCESS' text='WARN: Test coverage only 89% {build.status.text}']
But that won't send any notification. Do you have any other suggestions, please?
Set the coverage html as artifact and link to it from Teamcity. IE setup a new tab, it will look something like this.