none
VS2011 Test Unit with native C++ use of TestDir

    질문

  • Hello,

    I was using test unit under VS2010. I used

    "TestContext->TestDir"

    To get the path needed.

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

    How is it possible?

    thx


    • 편집됨 Sylvain Rony 2012년 4월 16일 월요일 오후 2:39
    2012년 4월 16일 월요일 오후 2:39

모든 응답

  • 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.

    http://blogs.msdn.com/b/visualstudioalm/archive/2012/03/08/what-s-new-in-visual-studio-11-beta-unit-testing.aspx

    http://msdn.microsoft.com/en-us/library/hh598953(v=vs.110).aspx

    Thanks.

    2012년 4월 16일 월요일 오후 6:56
  • 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.

    2012년 4월 18일 수요일 오전 8:18
  • 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

    2012년 4월 19일 목요일 오전 8:15
  • 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;
      
    BEGIN_TEST_CLASS_ATTRIBUTE()
     TEST_CLASS_ATTRIBUTE( "cube.mdl", 0)
    END_TEST_CLASS_ATTRIBUTE()
      
    public:
    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    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
    TEST_METHOD((TestHello))
    {
     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:
    BEGIN_TEST_METHOD_ATTRIBUTE(TestHello)
     TEST_WORKITEM("Cube.mdl")  /// the input data file allready added in my test project
    END_TEST_METHOD_ATTRIBUTE()

    TEST_METHOD((TestHello))
    {
     //but there I want to have the full path of my data input file, I found nothing
     CString l_Str = ???
    }

    Could anyone help me?

    2012년 4월 19일 목요일 오전 9:00
  • 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

    2012년 4월 20일 금요일 오전 3:03
  • 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

    2012년 4월 23일 월요일 오전 8:26