locked
Visual Studio 2015 Enterprise using MSTest as Test Framework does not include body of the method while generating a unit test RRS feed

  • Question

  • Hi,

    Using Visual Studio 2015, I created a cloud service. I then tried to create a unit test on one of the methods by right clicking on it and selecting "MSTest" as my Test Framework. While I see the unit test for the method getting generated, the body of the method is left out, in addition the input and outputs of the method are altered. 

    Is there something (like some setting, flag, or checkbox) that will help include the method body in the unit test method?

    Thanks





    Sunday, August 9, 2015 12:23 AM

Answers

All replies

  • Hi,

    Please follow the process as explained here -> Create and run unit tests with Visual Studio

    you can also follow Create unit test projects and test methods

    In your case specifically, Open your solution in Visual Studio. Then open the class file that has methods you want to test.

    • Right-click in a method in your code and choose Run IntelliTest to generate unit tests for the code in your method.

      Right-click in your method to generate unit tests

      IntelliTest runs your code many times with different inputs. Each run is represented in the table showing the input test data and the resulting output or exception.

      Exploration Results window is displayed with tests

      To generate unit tests for all the public methods in a class, simply right-click in the class rather than a specific method. Then choose Run IntelliTest. Use the drop-down list in the Exploration Results window to display the unit tests and the input data for each method in the class.


    Please mark as answer or vote as helpful if my reply does

    Sunday, August 9, 2015 12:43 AM
  • I think I did not explain the problem correctly. 

    I am using MSTest as the Test Framework. 

    For example, if I have the following Get method which has an input param of int and a return type of string, the uni test method created by MSTest framework, excludes the body of the method, in addition sets the return type of the method to void and removes the input parameter.

    public string Get(int id)         //return value is void and no param in the unit test method
    {
    int i =5;                         //Gets excluded from the unit test method
    i++;				  //Gets excluded from the unit test method
    string debug = i.ToString();      //Gets excluded from the unit test method
    return value;
    }

    I right click on the Get method, "Create Unit Tests", I select "MSTest" as my Test Framework. I get the following uni test created

    [TestMethod()]
    public void GetTest()
    {
        Assert.Fail();
    }




    Sunday, August 9, 2015 1:13 AM
  • Okay got it. Similar issue has been discussed at http://stackoverflow.com/questions/25304425/visual-studio-2013-doesnt-discover-unit-tests

    Please mark as answer or vote as helpful if my reply does

    Sunday, August 9, 2015 3:33 AM
  • I am afraid, I am lost. Please point me to the specific case where this has been discussed.
    Sunday, August 9, 2015 3:46 AM
  • I am afraid, I am lost. Please point me to the specific case where this has been discussed.

    Okay I did some research. I don't see any issue with your test case, this is the expected result. 

    Refer the article which describes the basic of using MS Test.  http://www.codeproject.com/Articles/784791/Introduction-to-Unit-Testing-with-MS-tests-NUnit-a

    Your unit test case must referring the namespace of your project.


    Please mark as answer or vote as helpful if my reply does

    Sunday, August 9, 2015 4:04 AM
  • ok, thanks, maybe this is the default behavior. But then, methods have many lines of code, why is the unit test just excluding them and creating just the skeleton of the method? It is of almost no use if you have to get the body of the method in each case, now consider if you had 100s of methods, that would become very inefficient.


    Sunday, August 9, 2015 4:37 AM
  • Hi ihaveanazurequestion,

    As you found, I agree with you and Rachit, it is expected behavior, and you need to write your own method to achieve your own requirement.

    I suggest that you should submit this feedback to Microsoft Connect feedback portal: http://connect.microsoft.com/VisualStudio/feedback/CreateFeedback.aspx, Microsoft engineers will evaluate them seriously.

    After you submit the feedback, you can post the link here which will be beneficial for other members with the similar issue.

    Best Regards,

    Edward


    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.


    Monday, August 10, 2015 6:30 AM
  • thanks, in my opinion, the generated test unit should have within it's body a call to the actual method so that we can write Assertions around it.


    ihaveacsharpquestion

    Tuesday, August 11, 2015 3:17 PM