sentryone / unittestgenerator

A unit test generation extension for Visual Studio
Apache License 2.0
25 stars 5 forks source link

Multiple issues on first use related to nuget packages #46

Open StingyJack opened 3 years ago

StingyJack commented 3 years ago

This seems to have problems with packages. I right clicked on a target assembly and chose Generate Tests and it started to and then put up a full screen error dialog SentryOne right click project and create tests

I figure there is some problem relating to private packages, so in the options I told it not to install referenced packages and changed it to use MSTest and Moq, deleted the csproj file and its folder that were created and repeated the test generation. This time generation worked,. except that running tests didnt work and reported this in the output window

---------- Starting test discovery for requested test run ----------
Test project MyProject.Tests does not reference any .NET NuGet adapter. Test discovery or execution might not work for this project.
It's recommended to reference NuGet test adapters in each test project in the solution.
Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Unable to find C:\Users\me\source\repos\ MyProject\ MyProject.Tests\bin\Debug\netcoreapp3.1\testhost.dll. Please publish your test project and retry.
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostPath(String runtimeConfigDevPath, String depsFilePath, String sourceDirectory)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.GetTestHostProcessStartInfo(IEnumerable`1 sources, IDictionary`2 environmentVariables, TestRunnerConnectionInfo connectionInfo)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, String runSettings)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyDiscoveryManager.DiscoverTests(DiscoveryCriteria discoveryCriteria, ITestDiscoveryEventsHandler2 eventHandler)
========== Test discovery aborted: 0 Tests found in 12.8 ms ==========

So I added the private nuget package and the MSTest adapter and then set the target framework to be netcoreapp31 (cant be netstandard for a reason I have read but disagree with) and that resolved the above error, and building now discovers the tests. However, running them reports No tests found to run. still. So I'm going to try a reboot, but figured I'd share this in case you wanted to know.

EDIT: After adding another empty unit test project from the VS templates, the basic package set is

  <PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.7.1" />
    <PackageReference Include="MSTest.TestAdapter" Version="2.1.1" />
    <PackageReference Include="MSTest.TestFramework" Version="2.1.1" />
    <PackageReference Include="coverlet.collector" Version="1.3.0" />

I was missing the first one in the generated project. Adding it fixes the test discovery problem

mattwhitfield commented 3 years ago

Sorry I didn't see this for some reason. Like the other issue, I may just remove support for generating the projects as it's never been that great.

StingyJack commented 3 years ago

Its easy to work around and would probably save you a ton of maintenance.

Without that do the config options still need to be present? Are the target projects test framework and mocking library detected automatically?

mattwhitfield commented 3 years ago

Are the target projects test framework and mocking library detected automatically?

No, but that is definitely something we could do. Also, since it has support for setting those in a config file - yes the default options become much less useful. But I guess they make sense from a discoverability standpoint at least (for new users).

mattwhitfield commented 3 years ago

So https://github.com/mattwhitfield/unittestgenerator has some updates for this. It will auto-detect the target frameworks, as well as selectively use FluentAssertions if that is present. The project generation is gone now - but the options for framework are still there (they are used if you allow generation without a target project) - they just get over-ridden if you have turned on auto-detection (which will be on by default).

A new version should be out in a couple of weeks - but it will have to be a different item in the marketplace as I no longer work for SentryOne 👍

StingyJack commented 3 years ago

@mattwhitfield - if a new version comes out and you cant mention it here, please create an issue in any of my repos to let me know about it, Even with some of the issues this one has its still earned a spot in my toolbox and recommendations when someone I work with asks about VS extensions.

mattwhitfield commented 2 years ago

Fixed in https://marketplace.visualstudio.com/items?itemName=MattWhitfield.Unitverse - and thanks, really appreciate it. If there are some issues outstanding for you, then please do let me know via https://github.com/mattwhitfield/unittestgenerator/issues 👍

mattwhitfield commented 2 years ago

@StingyJack just wanted to tag you in case you hadn't seen ^