Cannot find any coverage data (ASP.NET MVC2) - visual-studio-2010

I am having some issues with getting Code Coverage working with an out-of-the-box ASP.NET MVC2 Web App
VS2010 Ultimate, File > New Project > ASP.NET MVC 2 Web Application > Yes, Create unit test project with Visual Studio Unit Test. I then Rebuild All, Run All Unit Tests, Go to Code Coverage and get the following message:
Cannot find any coverage data (.coverage or .coveragexml) files. Check test run details for possible errors.
All the unit tests passed. (And I haven't touched a line of code yet)
I did find the following on the web:
http://www.vbforums.com/showthread.php?t=615377
which says to do the following:
Test -> Edit Test Settings -> Local
In the test settings dialog, click
"Data and Diagnostics" Ensure "Code
Coverage" are checked, and
double-click on it Check of the dll's
you want code coverage enabled for.
But, when I go to Test > Edit Test Seetings, all I see is the grayed out menu item stating "No Test Settings Available".
Any ideas?
Edit: slowly gaining traction. See: How to create the vsmdi/testrunconfig file when importing a Visual Studio test project?

I have had this same problem occur when I added a test project from another source (ie added to, but not created in the current solution). When doing this, local.testsettings, Solution.vsmdi, and TraceAndTestImpact.testsettings are NOT created inside your solution.
This fix is really quite simple, though. Simply right click on your solution and click Add -> New item. A new window will appear. On the left-hand side under General and Performance should be Test Settings. This should let you add a .testsettings file that you can now edit.
More information can be found here:
http://msdn.microsoft.com/en-us/library/ee256991%28v=vs.100%29.aspx

Related

Facing error in initialising Go Test Explorer in VS Code

As of last month, I am now facing an issue in VS Code where the go tests in my Go project do not show up in Test Explorer.
NOTE - I am able to run the tests directly from Codelens in the file, but as far as the Test explorer UI is concerned it cannot configure my tests.
This was previosly working in VS Code quite well with out any issues.
The Output from the Go module indicates the following error the first time I try opening the Test Explorer.
Failed to resolve tests: TypeError: Cannot read property 'groups' of null
Test Explorer view showing that tests are not found in workspace

Visual Studio 2022 Test Explorer doesn't show any tests with a File/New "Test" project

Using the latest VS...
I created a brand new project with this template...
Everything compiles fine, but the default test that is created doesn't show up in Test Explorer. I hit the green "play all" button and the output window shows 1 test found, but "No tests found to run.".
Is this a known issue? Or what do I need to do to make Test Explorer show all my tests?
I can right-click/Run the test with no issues. But nothing shows in Test Explorer...
The filters were set to show failed tests only. Once I fixed that, the test appeared.

How to specifiy the location for a unit test in VS 2010

When using VS 2010, I like to organize the projects in my solutions by creating them in subfolders in the OS. For example I would place a project called MySolution.Core.Shared in G:\Projects\MySolution\Core\Shared. I will also create a Solution folder in Solution Explorer to hold the project as well. This works well for other templates, but the automated unit test creation process does not. VS always creates the unit test project in the solution's root folder, so I have to then unload the test project, move the project (after closing VS or I get a file open error for some reason) and then reopen the solution and remount the project in the appropriate point in Solution Explorer.
Well, I was never able to find a true answer to this, but I did find an acceptable solution. Here are the steps I took:
Create the test project manually by first right clicking on the
solution folder where you wish to place your new tests and choosing
the Add -> New Project option.
Select the Tests->Test Project Template.
Give it an appropriate name and choose the appropriate Location in
the provided slots.
Go to the object/member you wish to test and select Create Unit
Tests in the right click menu.
Choose the test project you just created in the spot provided at the
bottom of the resultant dialog box.
Voila! You are done and your unit tests are now nice and snugly placed in your file structure of choice.

This Breakpoint Will Not Currently Be Hit, The Source Code is Different from the Original (even after cleaning/rebuilding)

.NET 4, console application. The project is set to 'Debug' mode. The breakpoint being set is in the primary/startup project. I have right-clicked -> Clean, and right-clicked -> rebuild, both on the Solution and project levels.
Following the instructions in this SO question, I have confirmed that my "Build and Run" options are set to 'prompt' for both 'When projects are out of date' and 'when build or deployment errors occur', and I am NOT getting a prompt when I F5 to build/run.
Also, the 'save all changes' under 'before building' is also selected (plus I manually saved them myself).
I monitored the output window of the application, see this line:
'MyApplication.exe': (Managed (v4.0.30319)): Loaded 'C:\exepath' Symbols Loaded.
I restarted the VS2010 instance. I restarted all open VS2010 instances (of other projects). I've even gone through a reboot.
However, the breakpoint I am setting in the startup project is a hollow-red circle, with the notice that 'This breakpoint will not currently be hit, The source code is different from the original', and, in fact, is never hit.
So, this is really 2 questions:
1) How do I fix this problem so I can properly breakpoint
2) When I see this, does that mean my code is executing from an older build?
I've had this problem once myself but that was on a vsto addin. In that case there were left over intermediate files under the users/appdata directories that were actually loaded instead of my app.
There is this blog article that has a whole load of possible reasons for this error and then a whole bunch more in the comments from other users
This can also happen if you have a solution with multiple projects, and have the wrong project selected as your startup project in VS2010 and VS2012.
Now, obviously, I wouldn't expect debugging to work if I have the wrong startup project selected -- the debugger is attaching itself to the wrong process!
But this error message (in my case) was terribly misleading. It made me think something else was wrong. I tried a bunch of solutions in this thread (nuking various /bin and output directories) when really it was something very simple (wrong startup process).
If you are using vb, check that you are building the project for the active solution configuration (Build, Configuration Manager..., Column under Build is checked. Also check the project properties, Compile tab, Advanced Compile Options, and Generate debug info is set to Full. Sorry I can't tell you where this may be in C#.
The only other time I've seen this is when two projects in the solution are referencing the same dll but they are referencing from different sources. One from a project reference and another from a file reference for example. If the "copy local" option is true, there would be the potential of overwriting the dll with an older version of the same dll.
My solution might help people who have signed the assembly.
After lot of head scratching for the past two days, I was able to resolve the same issue by doing the following simple steps:
Go to your Visual Studio project properties.
Go to the "Signing" tab.
Uncheck "Delay sign only" option if it is checked.
Now run your project and it should work.For me it did work.
In my case was this same problem (“The breakpoint will not currently be hit. The source code is different from the original version.”) caused by fact, that I tried add breakpoint to declaration:
DateTime dt;
bool b = DateTime.TryParse(null, out dt);
(first line of code)
So I assume that message is "universal" and may have many different causes.
This can happen if your system clock was changed since the last compile. Your PDB file will be different date than the one your are trying to debug. Delete the PDB files in the project and recompile.
I experienced the problem when Project > Properties > Web did not have "Enable Edit and Continue" selected. After enabling this feature the issue was corrected.
It is important to note that under Tools > Options > Debugging > Edit and Continue "Enable Edit and Continue" was selected, but it was not enabled for this project.
Just go to Tools / Import and Export Settings
Choose reset all settings then click Next
No, just resetl settings, ovewriting my current settings then click next
Choose your current language, por example C#. then click Finish
If you have multiple solutions open, try simply closing all Visual Studio instances and restarting only the instance you need.
In my experience this has happened when two branches of nearly identical code are open in different instances.
doing a "clean solution" from VS Build Menu might help you.
I had to go over all those steps to fix the issue on my computer.
Make sure that debug = "true" on your web.config
Clean and rebuild all projects
Delete every file inside the bin folder of all projects
Close and open Visual Studio, rebuild, and run the project again.
Go to your solution folder -> obj -> Debug - > delete the .dll file and build the solution again.

Enable code coverage in VS 2010 ultimate

This may seem a bit stupid, but I can't find the answer so:
My team just moved to VS2010 ultimate, and we'd like to enable code coverage. All the instructions I've found mention to open the Local.testsettings file and go to the "Execution Criteria" tab.
Well, I don't have this tab, and I do have VS2010 ultimate, which is supposed to support code coverage.
Help please :)
Noa
Do not forget about Button 'Configure' !!!
Select Test/Edit Test settings/your active settings/
Select Tab Data & Diagnostics,
Select the row Code Coverage
Check Enabled
Click the small Configure symbol on top of the grid.
Check all assemblies you want to collect code coverage info from...
There should be a Solution Items Folder in your Solution Exlorer. Double click the Local.testsettings file.
A new window should pop up. There is a list to choose from. Entries such as General, Roles, etc.
Select the entry "Data and Diagnostics". There you can enable code coverage.
Just to sum it up:
There should be Solution Items folder in your solution explorer, which should contain Local.testsettings file.
Double click it, go to Data and Diagnostics in opened window, enable Code Coverage there. Then click on Configure button there and check assemblys you wish Code Coverage to work for. Apply your settings, now Code Coverage should work.
In case you don't have Solution Items folder, or there is no Local.testsettings file, you might just create new Test Project. It will create Local.testsettings. You might remove new Test Project if you don't need it.
Here are the steps for VS 2010 Ultimate
Double click Local.Testsettings
Click on Data and Diagnostics tab
Check code coverage
Double click on that code coverage row
Select dll that you need to check the code coverage for
Click Apply and Close
If you can't find a local.testsettings file you can cause a new one to be created.
Simply create a new Test project, then delete it -- you should then have a Solution Items project folder with Local.testsettings and TraceAndTestImpact.testsettings files, and a vsmdi file.

Resources