locked
Create Unit Tests - not working VS Professional 2015 C# RRS feed

  • Question

  • When attempting to generate a unit test using the 'Create Unit Tests' menu item, receive error dialog stating that the action si valid only within a public method/class - which it is.   Subsequently the 'Create Unit Tests' menu item disappears from the context menu and isn't available at all - any file, or method.  

    What is probably relevant is that prior to the upgrade to VS 2015  from VS 2013 I used 'ALM Rangers Generate Unit Test' extension - which does not have support for VS 2015 as  - the functionality was added back in natively.  

    If I create a new solution and project - I am able to successfully use the 'Create Unit Tests' menu item.   

    Cannot figure out what the upgrade incompatibility  is, or how to remedy it?  

    Suggestions?

    Thanks, Ted.

    
    Wednesday, August 26, 2015 7:19 PM

Answers

  • Hi ttrela,

    >>When attempting to generate a unit test using the 'Create Unit Tests' menu item, receive error dialog stating that the action si valid only within a public method/class - which it is.  

    Could you please share me a screen shot where you get the error dialog stating that the action si valid only within a public method/class?

    I tried to create a simple C# class library and then I right click select the Create Unit tests.

    and then get the error dialog like you said in my side.

    So if you get same issue like I said that, I did some research about it, I know that since unit test is used to test class method.

    Therefore, you will need to right-click the class method and then select Create Unit tests, you will get a create unit tests dialog.

    I suggest you could try to check this issue in your issue.

    >>What is probably relevant is that prior to the upgrade to VS 2015  from VS 2013 I used 'ALM Rangers Generate Unit Test' extension

    Did you install the 'ALM Rangers Generate Unit Test' extension on VS2015?

    Whether you open a VS2013 Unit test project from VS2015 and then get the above error message?

    Please share me more message about your issue so that we will further help you check this issue.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Tina-Shi Friday, August 28, 2015 6:02 AM
    • Marked as answer by Tina-Shi Wednesday, September 2, 2015 6:49 AM
    Friday, August 28, 2015 6:02 AM

All replies

  • Thank you for reporting the issue about the "Create Unit Tests" menu item disappearing. This seems intermittent and reopening the solution should bring back the menu item.

    Also, there is no upgrade incompatibility with the 'ALM Rangers Generate Unit Test' extension.

    Thursday, August 27, 2015 7:47 AM
  • Hi ttrela,

    >>When attempting to generate a unit test using the 'Create Unit Tests' menu item, receive error dialog stating that the action si valid only within a public method/class - which it is.  

    Could you please share me a screen shot where you get the error dialog stating that the action si valid only within a public method/class?

    I tried to create a simple C# class library and then I right click select the Create Unit tests.

    and then get the error dialog like you said in my side.

    So if you get same issue like I said that, I did some research about it, I know that since unit test is used to test class method.

    Therefore, you will need to right-click the class method and then select Create Unit tests, you will get a create unit tests dialog.

    I suggest you could try to check this issue in your issue.

    >>What is probably relevant is that prior to the upgrade to VS 2015  from VS 2013 I used 'ALM Rangers Generate Unit Test' extension

    Did you install the 'ALM Rangers Generate Unit Test' extension on VS2015?

    Whether you open a VS2013 Unit test project from VS2015 and then get the above error message?

    Please share me more message about your issue so that we will further help you check this issue.

    Best Regards,


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.


    • Edited by Tina-Shi Friday, August 28, 2015 6:02 AM
    • Marked as answer by Tina-Shi Wednesday, September 2, 2015 6:49 AM
    Friday, August 28, 2015 6:02 AM
  • I get the same error on the following trivial program. I am unable to add unit tests to it. I close and reopen Visual Studio Enterprise 2015 and the menu comes back, only to go away again as soon as I try to add a unit test.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using Microsoft.VisualStudio.TestTools.UnitTesting;
    
    namespace Scratch
    {
        public class Program    //Originally this was just class Program
        {
            static void Main(string[] args)
            {
    
                Console.WriteLine("Hello world!");
    
            }
    
            public static string TruncateOld(string value, int length)
            {
                string result = value;
                if (value != null) // Skip empty string check for elucidation
                {
                    result = value.Substring(0, Math.Min(value.Length, length));
                }
                return result;
            }
    
            public static string Truncate(string value, int length)
            {
                return value?.Substring(0, Math.Min(value.Length, length));
            }
    
    
        }
    }

    Here's a screenshot:

    Add Unit Tests Error Message

    Also, I've never installed 'ALM Rangers Generate Unit Test.'

    Steps to reproduce in VS 2015 Enterprise:

    1. Create a new console app
    2. Add a ref to the UnitTestFramework
    3. Add the attached code for Program.cs and then try to add a unit test.

    Here's my version info:

    Microsoft Visual Studio Enterprise 2015
    Version 14.0.25425.01 Update 3
    Microsoft .NET Framework
    Version 4.6.01590
    
    Installed Version: Enterprise
    
    Architecture and Modeling Tools   00322-80000-00000-AA932
    Microsoft Architecture and Modeling Tools
        
    UML® and Unified Modeling Language™ are trademarks or registered trademarks of the Object Management Group, Inc. in the United States and other countries.
    
    Visual Basic 2015   00322-80000-00000-AA932
    Microsoft Visual Basic 2015
    
    Visual C# 2015   00322-80000-00000-AA932
    Microsoft Visual C# 2015
    
    Visual C++ 2015   00322-80000-00000-AA932
    Microsoft Visual C++ 2015
    
    Visual F# 2015   00322-80000-00000-AA932
    Microsoft Visual F# 2015
    
    Windows Phone SDK 8.0 - ENU   00322-80000-00000-AA932
    Windows Phone SDK 8.0 - ENU
    
    Add New File   3.5
    The fastest and easiest way to add new files to any project - including files that start with a dot
    
    ASP.NET and Web Tools 2015.1   14.1.20907.0
    ASP.NET and Web Tools 2015.1
    
    ASP.NET Web Frameworks and Tools 2012.2   4.1.41102.0
    For additional information, visit http://go.microsoft.com/fwlink/?LinkID=309563
    
    ASP.NET Web Frameworks and Tools 2013   5.2.40314.0
    For additional information, visit http://www.asp.net/
    
    Azure App Service Tools v2.9.5   14.0.20810.0
    Azure App Service Tools v2.9.5
    
    Azure Data Lake Node   1.0
    This package contains the Data Lake integration nodes for Server Explorer.
    
    Azure Data Lake Tools for Visual Studio   2.1.0000.0
    Microsoft Azure Data Lake Tools for Visual Studio
    
    Bundler & Minifier   2.1.279
    Adds support for bundling and minifying JavaScript, CSS and HTML files in any project.
    
    Common Azure Tools   1.8
    Provides common services for use by Azure Mobile Services and Microsoft Azure Tools.
    
    File Icons   1.5
    Adds icons for files that are not recognized by Solution Explorer
    
    File Nesting   2.5.63
    Automatically nest files based on file name and enables developers to nest and unnest any file manually
    
    GitHub.VisualStudio   1.0
    A Visual Studio Extension that brings the GitHub Flow into Visual Studio.
    
    Image Optimizer   3.6.93
    Uses industry standard tools to optimize any JPEG, PNG and Gifs - including animated Gifs. Can do both lossy and lossless optimization.
    
    Image Sprites   1.3.40
    Boost your website's performance by creating image sprites to reduce the amount of HTTP requests needed.
    
    JavaScript Language Service   2.0
    JavaScript Language Service
    
    JavaScript Project System   2.0
    JavaScript Project System
    
    Markdown Editor   1.8.159
    A full featured Markdown editor with live preview and syntax highligting. Supports GitHub flavored Markdown.
    
    Microsoft .NET Core Tools (Preview 2)   14.1.20907.0
    Microsoft .NET Core Tools (Preview 2)
    
    Microsoft Azure Hive Query Language Service   2.1.0000.0
    Language service for Hive query
    
    Microsoft Azure Mobile Services Tools   1.4
    Microsoft Azure Mobile Services Tools
    
    Microsoft Azure Tools   2.9
    Microsoft Azure Tools for Microsoft Visual Studio 2015 - v2.9.40715.2
    
    NuGet Package Manager   3.5.0
    NuGet Package Manager in Visual Studio. For more information about NuGet, visit http://docs.nuget.org/.
    
    Open Command Line   2.1.176
    Opens a command line at the root of the project. Support for all consoles such as CMD, PowerShell, Bash etc. Provides syntax highlighting, Intellisense and execution of .cmd and .bat files.
    
    Package Installer   1.8.85
    Makes it easier, faster and more convenient than ever to install Bower, npm, JSPM, TSD, Typings and NuGet packages to any project
    
    PreEmptive Analytics Visualizer   1.2
    Microsoft Visual Studio extension to visualize aggregated summaries from the PreEmptive Analytics product.
    
    RenameVSWindowTitle 3   1.0
    Information about my package
    
    SQL Server Data Tools   14.0.60519.0
    Microsoft SQL Server Data Tools
    
    ToolWindowHostedEditor   1.0
    Hosting json editor into a tool window
    
    TypeScript   1.8.36.0
    TypeScript tools for Visual Studio
    
    Visual Studio Spell Check Everywhere   VSSpellCheckEverywhere
    An extension that enables spell checking within any Visual Studio file editor or tool window that uses WPF text boxes.
    https://GitHub.com/EWSoftware/VSSpellChecker
    
    Visual Studio Spell Checker   VSSpellChecker
    An editor extension that checks the spelling of comments, strings, and plain text as you type or interactively with tool windows.
    https://GitHub.com/EWSoftware/VSSpellChecker
    
    Visual Studio Tools for Apache Cordova   Update 10
    Visual Studio Tools for Apache Cordova
    
    Visual Studio Tools for Universal Windows Apps   14.0.25527.01
    The Visual Studio Tools for Universal Windows apps allow you to build a single universal app experience that can reach every device running Windows 10: phone, tablet, PC, and more. It includes the Microsoft Windows 10 Software Development Kit.
    
    Web Accessibility Checker   1.3.33
    The easiest way to perform accessibility checks on any ASP.NET web application. Fully customizable and support all the major international accessibility standards.
    
    Web Essentials 2015.3   3.0.235
    Adds many useful features to Visual Studio for web developers. Requires Visual Studio 2015
    
    Xamarin   4.1.1.3 (34a92cd)
    Visual Studio extension to enable development for Xamarin.iOS and Xamarin.Android.
    
    Xamarin.Android   6.1.1.1 (7db2aac)
    Visual Studio extension to enable development for Xamarin.Android.
    
    Xamarin.iOS   9.8.1.4 (3cf8aae)
    Visual Studio extension to enable development for Xamarin.iOS.


    Following a suggestion on stack overflow I got rid of everything from my Program.cs except for the Main and added a new Public Class1 with the following code (I still get the error and the menu goes away):

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    
    namespace Scratch
    {
        public class Class1
        {
    
    
            public Class1()
            {
    
            }
    
            public string TruncateOld(string value, int length)
            {
                string result = value;
                if (value != null) // Skip empty string check for elucidation
                {
                    result = value.Substring(0, Math.Min(value.Length, length));
                }
                return result;
            }
    
            public string Truncate(string value, int length)
            {
                return value?.Substring(0, Math.Min(value.Length, length));
            }
    
    
        }
    }
    

    Tuesday, September 20, 2016 7:58 PM