locked
MSTest unit test tool: Null pointer check RRS feed

  • Question

  • Hi,

    I want to write test cases to check the parameter and the NULL pointer in C++ using MSUnit Test.

    Could anyone please hlp me how to do.

    Thanks

    Lokanath 

    • Moved by Shu 2017 Wednesday, August 27, 2014 3:07 AM it is a Unit testing thread
    Tuesday, August 26, 2014 9:44 AM

Answers

  • Hi Lokanath,

    Yes, your understanding is correct. You can send two parameters in that method and compare the return value like below:
            Assert::AreEqual(MyProject::compute(2,3), 6);

    Reference: Adding unit tests to existing C++ applications This document told you that how to write unit test for C++ code.

    If you have further questions, please feel free to let us know or open a new thread, we will try our best to help you.

    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.

    • Proposed as answer by Amanda Zhu Tuesday, September 2, 2014 1:25 AM
    • Marked as answer by Amanda Zhu Tuesday, September 2, 2014 9:10 AM
    Thursday, August 28, 2014 2:08 AM

All replies

  • Also i want to understand the below:

    I have a method called int compute(int x,int y). This method takes two int value and returns the result.

    So i am able to write the unit test by sending some parameter and checking the return value. Fine.

    __________________________________

    But i have one more method called void EstablishConnection(). This method neither take any argument nor return anything. Then how should i write the unit test case for this.

    I am using MStest 2010.

    Thanks In advance.

    Tuesday, August 26, 2014 10:13 AM
  • Hi,

    I will move your thread to unit test forum for a better support.

    VS Unit Test Forum

    Best regards,

    Shu Hu


    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.

    Wednesday, August 27, 2014 3:03 AM
  • Hi Lokanath,

    Yes, your understanding is correct. You can send two parameters in that method and compare the return value like below:
            Assert::AreEqual(MyProject::compute(2,3), 6);

    Reference: Adding unit tests to existing C++ applications This document told you that how to write unit test for C++ code.

    If you have further questions, please feel free to let us know or open a new thread, we will try our best to help you.

    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.

    • Proposed as answer by Amanda Zhu Tuesday, September 2, 2014 1:25 AM
    • Marked as answer by Amanda Zhu Tuesday, September 2, 2014 9:10 AM
    Thursday, August 28, 2014 2:08 AM