Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where is Create Unit Test in VS 2017?

I understand that this question has been asked before on SO and it appears that this feature was removed from VS at some point. But I am looking at a Microsoft tutorial right now and that says there should be a Create Unit Test function in VS 2017.

I'm trying to test ASP.NET Core MVC controllers. I have followed the steps for creating a test project. But I still can't see any such option when I right click a namespace/class/method.

EDIT: I'm using Visual Studio 2017 Community Edition

like image 977
lfk Avatar asked Mar 18 '17 16:03

lfk


People also ask

How do I run unit test cases in Visual Studio 2017?

Run tests in Test Explorer If Test Explorer is not visible, choose Test on the Visual Studio menu, choose Windows, and then choose Test Explorer (or press Ctrl + E, T). As you run, write, and rerun your tests, the Test Explorer displays the results in a default grouping of Project, Namespace, and Class.

How do you create a VS unit test?

To get started, select a method, a type, or a namespace in the code editor in the project you want to test, right-click, and then choose Create Unit Tests. The Create Unit Tests dialog opens where you can configure how you want the tests to be created.


1 Answers

The answer below relates to .NET Core/Standard only. If you're missing the Create Unit Tests option for a full .NET Framework project see here.

Current status: It's now working for .NET Core!

I now have the Create Unit Tests context menu in my Core 3 solution running on Visual Studio Professional 2019 Version 16.3.0 Preview 3.0. Not sure exactly when it reappeared as I've been updating regularly with each new preview version.

History

See the updates below for more history and details.

Original answer June 2017

This GitHub entry from Microsoft's Jayarani Garg, confirmed it is only available for projects targeting the full .NET framework:

Jayarani Garg [MSFT] · Feb 27 2017 at 06:09 AM Hi,

Thank you for your feedback. "Create Unit Test" is currently not supported for .Net Core projects.

That's by design rather than a bug according to this Visual Studio Team comment on that same Visual Studio Developer Community page:

Visual Studio Team ♦♦ · Mar 10 2017 at 01:06 PM

Thank you for your feedback! The Visual Studio team has determined that this issue is not a bug. However, we will consider this feedback and have created https://github.com/Microsoft/vstest/issues/592 to track this. Please feel free to vote for the issue.

The github issue referred to above on the Microsoft VS Test repo Create Unit Test Context Menu Missing (.net core projects) is slightly confusing. It's asking for this feature to be added for .NET Core projects too but then a Microsoft employees talk about having a fix for an issue. I believe that employee is referring to the old bug where the context menu option wasn't working for full .NET framework projects either as discussed in this question which is also mentioned in that thread. As far as I can see that thread is not saying they've added the menu option for .NET Core projects.

I've also just checked on a copy of Visual Studio Professional 2017, version 15.2 (26430.6) and I do have the Create Unit Tests option for a project that targets the full .NET framework (this one targets .NET Framework 4.5.1):

Create Unit Test menu item present

But I don't have it for a project that targets .NETCoreApp 1.1:

Create Unit Test menu item missing

Update June 2018

Microsoft have taken notice of the upvotes for the feature request and are planning to introduce the context menu option for .NET Core projects in release 15.8:

Manish Jayaswal [MSFT] replying to Daniel Tibi · Apr 06 2018 at 10:30 PM

Getting this functionality added to .NET Core projects requires some significant changes in the new project system - which drives the .NET Core projects. This work is getting tracked in project system GitHub repo in this issue (https://github.com/dotnet/project-system/issues/3425) . This issue is expected to be resolved in 15.8 release timeframe so unfortunately, create unit test functionality for .NET Core projects would not be available in the upcoming 15.7 release. We fully understand that this is a key feature and would do our best to make it available as early as possible.

Update July 2018

The Create unit test method stubs with the Create Unit Tests command page has been updated now to reflect that this doesn't work for .NET Core.

Update August 2018

As pointed out by @gartenriese below, the GitHub issue 3425 Microsoft described as tracking this work was moved to the 15.9 milestone on 02 August 2018.

Update January 2019

The unit testing feature seems to be reliant on, or blocked by, another part of the development. That part is now slated for VS 16.1, i.e VS 2019, and is also further down the priority list than EF Core 3.0 (which is one of the main features of VS 16) according to this GitHub post by Microsoft's David Kean.

May 2019 update

The Create Unit Tests context menu option isn't supported (yet) for projects that target .NET Core and .NET Standard.

The documentation was updated to reflect this in July 2018 and now states:

The Create Unit Tests menu command:

  • Is available in the Community, Professional, and Enterprise Editions of Visual Studio 2015 and later.
  • Supports only C# code that targets the .NET Framework.
  • Is extensible, and supports emitting tests in MSTest, MSTest V2, NUnit, xUnit format.
  • Is not yet available in .NET Core projects.

This feature was slated for release in Version 15.9 of Visual Studio, but now appears to have been pushed back to Version 16.1.

I've tested this in a .NET Core 2.2 project in Visual Studio Professional 2019 RC (version 16.0.0) and I can confirm it's still not working there - as expected as per the above answer.

I've also just tested Visual Studio Professional 2019 Preview (version 16.1.0 Preview 2.0) and it's not available there either, so it doesn't look like Microsoft have got to this yet.

like image 153
tomRedox Avatar answered Sep 24 '22 18:09

tomRedox