I'm trying to set up unit testing with code coverage in VS2008, for a C++/CLI DLL which is compiled with /clr (not /clr:safe or /clr:pure - it has to be /clr because it uses MFC).
The unit tests work perfectly but the coverage information only works if I compile with /clr:safe or /clr:pure. For /clr the Code Coverage Results window shows the following message:
Empty results generated: none of the
instrumented binary was used. Look at
test run details for any
instrumentation problems.
I've also tried "going offroad" but when I load the coverage file into VS, it also contains empty results.
Annoyingly I can't find anywhere that specifically says whether Code Coverage works with /CLR, so I just had to try it myself.
If it should work, can anyone see what I'm doing wrong here?
[File]->[New]->[Project]
Select Class Library, enter MyProj as the project name, click OK
Right-click on MyProj project, select [Properties]
Select [Configuration Properties]->[General]
Ensure "Common Language Runtime support" is set to /CLR
Add this code to Class1:
public:
static int calc() { return 69; }
Build solution
[Test]->[New Test]->[Unit Test], click OK, click Create
Add this code to TestMethod1:
Assert::AreEqual(MyProj::Class1::calc(), 69);
Right-click on TestProject1 project, select [References]
Click "Add New Reference"
Select MyProj in the "Projects" tab, click OK, click OK again
[Test]->[Edit Test Run Configuration]->[Local Test Run]
Select [Code Coverage]
Check MyProj.dll, click Apply, click Close
[Test]->[Run]->[All Tests in Solution]
The Test Results window shows TestMethod1 has passed.
The Code Coverage Results window shows the following message:
Empty results generated: none of the
instrumented binary was used. Look at
test run details for any
instrumentation problems.
Right-click on MyProj project, select [Properties]
Select [Configuration Properties]->[General]
Change "Common Language Runtime support" to /CLR:SAFE or /CLR:PURE, click OK
Build solution
[Test]->[Run]->[All Tests In Solution]
The Test Results window shows TestMethod1 has passed.
The Code Coverage Results window now shows correct coverage information.
Based on http://msdn.microsoft.com/en-us/library/ms182534.aspx
1-project must be in debug
2.-in the project properties you must select x 86 platform.
3 Unregister the project being tested in the GAC.
Yeh, I think it all has to be in CLR:Safe project to work. I don't fully understand why, but I'm in the same boat as you.
Related
On my M1 mac, using Xcode 13.3, I created a package and displayed the code coverage bar (Editor menu –> Code Coverage).
After running tests, there is no indication of code coverage at all in the source code.
How do I get code coverage when testing a package?
The problem is that you didn't turn on Code Coverage for the library's scheme. Turn it on:
See the checkbox at the bottom: Code Coverage? Check that checkbox.
Now run the package test and coverage will be gathered. The best way to see it, in my experience, is actually in the report navigator:
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.
Is there a way to run all test in an root pom and collect test coverage in Intellij Idea ?
Create a Run Configuration that will look for tests in the whole project. Make sure that you choose All in package and In whole project in the configurations dialog:
Make sure that you choose the <default> package in the Choose Package dialog.
Now you can select to run this configuration using Run 'All in project' with Coverage:
The result will be presented in a separate coverate window:
And you will also see the result in the Project View window for a fast overview:
Right click on the parent module (root pom), and select Run 'All Tests' with Coverage.
There is a 'Coverage' plugin, which may not be enabled by default.
Find it at File->Settings->Plugins.
This will enable the 'Run with Coverage' buttons and menu items.
A short official overview video is here: Code Coverage by IntelliJ IDEA
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.
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