New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fine Code Coverage extension forcing all tests to run even when running a single test #27
Comments
I feared this curve ball would show up in the issue list some day. Under the covers, the extension runs:
Unfortunately, neither allows for fine-grained single (or a few) test execution/coverage scenarios. I sincerely apologize for this. I don't think i can deliver this feature. |
@FortuneN When running |
Thanks @alex-jitbit I figure i can also use module and class filters (which would be compatible for both openCover and coverlet down to single class level; i'm hoping to always be able to support the same features for both) The missing part of this puzzle is "how do i know which tests were run". FYI: I'm reopening the issue with this renewed interest. |
@Pompeoar You could just disable the addin until you need to get coverage. |
@tonyhallett That's pretty much how I've worked around it. |
@tonyhallett Maybe we could provide a simple Enable/Disable toggle on the Fine Code Coverage display window. This is far from the required solution but it could be a convince to be able to easily switch. |
@FortuneN I was going to suggest that. As I said to you I have an idea. For coverlet it would mean lo longer running coverage after tests have run. The collector driver facilitates this. Fine Code Coverage would need to just watch the TestResults folder for the emitted cobertura file. The difficulty is knowing this path as it is specified in .runsettings and is not available by reflection from test container. There is an exported internal class that provides this information for each test container. Getting these run settings is necessary to replicate Vs regardless of the collector. This is not currently implemented. An alternative is just a button and textbox for runsettings path and then the TestResults path and the Data collector can easily be added by Fine Code Coverage. After Christmas I can provide further details |
In addition I think that when tests have finished it is possible to get stats on tests passed failed skipped through reflection. If not using the data collector and having to re-run tests these values could be used to determine if coverage should be run. |
It should be possible in one form or another. |
If i'm not mistaken, i explored the data collector approach when i started. <PackageReference Include="coverlet.collector" Version="x.x.x"> Don't get me wrong, I'm currently using that to generate and publish coverage reports for my Azure DevOps builds. |
The package reference provides the collector dll and an msbuild target that makes the path to the collector available to the test framework so you only have to pass the friendly name. Aside from deterministic builds there is no need for the package reference or msbuild changes. As long as we provide the DLL and can provide the path. Path can be a command line argument or in the runsettings. The latter is preferable. The advantages of the collector is that there is no need to repeat the tests and as is mentioned on the coverlet site only the data collector is free from known issues that users of Fine Code Coverage could encounter. So no muss no fuss could have fuss. |
In fact coverage is an opt in feature and perhaps this is how Fine Code Coverage should work. Just add a button as per https://docs.microsoft.com/en-us/visualstudio/test/using-code-coverage-to-determine-how-much-code-is-being-tested?view=vs-2019#analyze-code-coverage. Discuss further in a few days. Happy Christmas |
I am are of that. That's the case with:
FCC goes in a different direction by choice. I started FCC after seeing the magic of Live Unit Testing and the ultimate dream for FCC is a user experience close to that (for code coverage). The user does not have to wait for the coverage process to end unless they actually want to see the results. |
Anyone who has ui tests will never want the full suite run automatically each time a single test is run and will have to switch on which is not much different to a button. Running a background thread for a large test suite would have a impact on Vs. With regards to runsettings. Anyone who uses runsettings data in their tests will currently not be able to use the addin at all. |
We will need to get to point where we have high efficiency (i.e. run/re-run only what needs to be re-run). Also, we can (in the future) include the ability to limit what gets run automatically.
Currently, that's handled by
(I know coverlet and report-generator are runnable in-process as libraries; i never checked OpenCover coz by the time i integrated it, i had already made the choice to run CLIs) I intend to move the code under the 'Core' folder into an external micro-web-server process.
I got the idea from Omnisharp.
I'm currently using runsettings in my work projects; I don't have a problem. Speaking of dreams, one of mine is to get listed on dotnet-foundation list |
The coverlet targetargs does not have run settings. Simple as. No repro required. |
I agree. .NET CORE
It does. coverlet /path/to/test-assembly.dll --target "dotnet" --targetargs "test /path/to/test-project --no-build"
Thus you can apply all the args that are possible for dotnet test and they include '--settings'
NET FRAMEWORK For .net framework we can have runsettings support through the vs test console (MsTestPlatform in FCC)
SOOOOOOO We can do the runsettings fix for both .net core (coverlet) and .net framework (opencover). We should span a new issue for runsettings support. |
Your args do not. I am fully aware that they can ! As I have already said this information does not appear to be available with reflection in Operation__StateChanged but is available if you create your own test adapter. The question is - if you create a fake adapter just to catch the run settings in discovery is that sufficient to be always notified of the current settings. In a couple of days when I return to work I can provide what I have found so far in terms of documentation and internal classes. We can then discuss approaches. We could just add to Vs options additional testargs. I still think that it should be possible to use the collector. As for the other points that you raised e.g only running tests for changed code we can discuss that too. For that you would need to use Roslyn. |
I will add an issue tomorrow morning on runsettings and add the information that I found. If you wish to tackle it then proceed as I will not be able to look at it for a couple of days. If you can wait those days I can spare some hours to fix it assuming the information is available. |
I found this e.Operation.Configuration.UserRunSettings.LastRunSettingsFilePath |
Yes but that's no good. There is a solution method there as well but looking at the source I could not see how it could be a runsettings that is from the user choice. If it was possible then you could read the project file to see if it specified runsettings. |
During my research when i started the project, i found this article : |
Why? |
Well I think it will be no good. Because of Last. What do you get first ? I have read the source with Reflector and ruled it out. Do you have Reflector or DotPeek ? In the code add a line to get the assembly location and then decompile in one of them. |
Yes that is the test adapter that I am referring to. |
Another spanner to throw in the works. Is the reflection code safe as is ? Is it possible for custom test adapter to discover containers that are not the type you are expecting ? |
If you can find the solution runsettings method - sorry don't have the details as not at my laptop you could test if the path is correct when changing run settings in vs. As I said before I have found an internal class that seems to have the logic that is required for runsettings on a project basis. I can send that tommorow. I did try the custom adapter approach - as an asset in the vsix. The details are in the link above I think. Unfortunately could not get it to be loaded in the short time that I tried. See if you can get it to work. You can check Nunit if you want to compare your setup. |
I wasn't aware of project level run settings; All of mine are solution level. A quick google search turned up the following link.
The first is what i've been using.
I don't know This ms docs article confirms the 3 approaches |
There is a Microsoft page dedicated to run settings. Auto detect solution, choose run settings for solution or project level in project file. As for reading from the project file. Easy to read if the user follows the docs but they could use any msbuild property they like as part of the path and then no. |
Yes that is it. |
If you don't want to use Reflector or DotPeek the source is available on GitHub. For instance the implementation of IRunSettings https://github.com/microsoft/vstest/blob/603d9bc4bbd10bdffedc1ce0e15f978dc157c32f/src/Microsoft.TestPlatform.Common/RunSettings.cs |
I have dotPeek (stand-alone); I'm not sure how to use it the way you've described. (I haven't used Reflector since it stopped being free) |
Not at laptop so cannot help much. Get the type of UserRunSettings e.Operation.Configuration.UserRunSettings.LastRunSettingsFilePath |
Or search the GitHub repo once you have the type name. |
public string LastRunSettingsFilePath => this.hostState.Value.IsOpened ? this.runSettings.Data.LastRunSettingsFilePath : (string) null; Don't answer now! lol |
There is a method that should provide the solution settings. Cannot remember the name though. Have you checked the methods ? I have the details on my laptop if you can wait until tomorrow |
I think I have written the necessary code. Testing it now, so hold back on doing any further work |
Ok it works and it is with reflection so you are right that it was achievable although we may not have found the necessary code if I had not used Reflector on C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\Common7\IDE\CommonExtensions\Microsoft\TestWindow\Microsoft.VisualStudio.TestWindow.Core.dll. As I said before there was a class that provided the logic that we required - ContainerRunSettingsProvider. Here is the reflection version of that code.
So usage
I will leave the full implementation of the code to you ! - i.e how to deal with the async file retrieval and the passing of the run settings file to Coverlet / OpenCover. It has been tested with the auto detect run settings, a specific solution run settings and also with run settings specified in the project file ! |
Of course all of this reflection is liable to break. microsoft/vstest#1830 |
I'm sure it will at some point during a VS version increase.
!!!!!!!!!!!!!!!!!!! YOU ARE THE MAN !!!!!!!!!!!!!!!!!!!
I'll start crafting. |
@FortuneN you may be interested in this as a method of not running coverage combined with user options.
|
That would a nice feature to have. |
@Pompeoar Soon there will be a way to turn off auto coverage from the tool window. |
Installed product versions
Description
With the extension enabled, trying to run a single test results in the test being run, and then all tests being run.
Steps to recreate
Current behavior
1 test passed ... then 1 Failed and 1 Passed.
Expected behavior
1 test passed.
Side Notes
This is particularly troublesome for larger test libraries and integration tests in particular.
I spent some time troubleshooting xunit and then visual studio settings before I found this. Disabling things like "discover tests in realtime" (options > test > general) does not fix this.
Pics to help: Note I did not run the second test
And yet both ran
The text was updated successfully, but these errors were encountered: