VS2011 Test Unit with native C++ use of TestDir RRS feed

  • Question

  • Hello,

    I was using test unit under VS2010. I used


    To get the path needed.

    If found nothing with native C++: to do the same.

    How is it possible?


    Monday, April 16, 2012 2:39 PM

All replies

  • Hi Sylvain,

    For managed cpp unit testing (which was available in VS2010 also) one should use "VS 2010 Managed Test Project" and not "Native Unit Test Project".

    Native unit testing is a new feature in VS2011 and was not available in VS2010. It uses new meta unit testing framework available in VS2011 for test case execution but has a different syntax/features than managed unit testing or VS2010 unit testing.  It doesn't have MsTest TestContext equivalent functionality.




    Monday, April 16, 2012 6:56 PM
  • Thks for the answer Dhruv K.

    Now we are using VS2011 so Native unit testing. So I couldn''t not use TestContext and it's "testDir" function.

    But How could I get the path or directory path of my input datas files (as I did with attribute and testContest)? 

    I didnt't find any way to get it.

    Wednesday, April 18, 2012 8:18 AM
  • Hi Dhruv K,

    Thank you for your friendly assistance.

    Hi Sylvain,

    Thank you for posting in the MSDN forum.

    I did some research about this issue, and it seemed that it used TestRunDirectory instead of the TestDir Property in VS2011. See TestContext::TestDir Property. Hope it could help.

    Since my C++ knowledge is not very rich, if no help, would you mind sharing us your projects?

    If there's any concern, please feel free to let us know.

    Best Regards,

    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Thursday, April 19, 2012 8:15 AM
  • Hi jack Zhai,

    Thank you for your answer.
    Previously, with MS2010. I used test, then in managed C++. I did more or less:

    TestContext^ testContextInstance;
     TEST_CLASS_ATTRIBUTE( "cube.mdl", 0)
    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    property Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ TestContext
     Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ get()
      return testContextInstance;
     System::Void set(Microsoft::VisualStudio::TestTools::UnitTesting::TestContext^ value)
      testContextInstance = value;

    TEST_WORKITEM("Cube.mdl")  /// my input data file added in my test project
     System::String^ l_strDir = TestContext->TestDir;
     ///then test my programme with "l_strDir\Cube.mdl"


    Nowdays, with visual 2011 textContext doesn't exist anymore because we have to use Native C++.
    So I still add my input data file in my project.

    I can do:
     TEST_WORKITEM("Cube.mdl")  /// the input data file allready added in my test project

     //but there I want to have the full path of my data input file, I found nothing
     CString l_Str = ???

    Could anyone help me?

    Thursday, April 19, 2012 9:00 AM
  • Hi Sylvain,

    Glad to receive your reply.

    Do you mean that you could use the "TestContext->TestDir" well in VS2010?

    The MsTest TestContext equivalent functionality is added to your unittest.cs file automatically in VS2010, but it doesn't have the MsTest TestContext equivalent functionality in VS2011. Based on my understanding, we could try to add the code manually in VS2011, and check it.

    In addition, I am trying to involve someone familiar with this topic to further look at this issue. There might be some time delay. Appreciate your patience.

    Best Regards,

    Jack Zhai [MSFT]
    MSDN Community Support | Feedback to us

    Friday, April 20, 2012 3:03 AM
  • Hi Jack Zhai,

    With VS2010, everything was OK and works well.

    But now I use VS2011. I try to add manually some code, but MsContext doen't exist, I think I should use something like MetaData. But what? I hope MSFT, will add a functionnality to get the path of an input data file (like a text file...). It would be really usefull and necessary!

    Thx a lot Jack Zhai.

    I hope I will some news of you later.

    Best regards

    Monday, April 23, 2012 8:26 AM