locked
How do I get VS11 C++ Unit Tests to recognize WinRT objects? RRS feed

  • Question

  • I'm trying to create a new C++ unit testing project in order to test my WinRT Component DLL. However, I can't seem to get the unit tests to run any sort of WinRT code.

    All that I've done at this point is created a native uniting project, and in the properties, I've enabled "Metro Style App Support". When I try to run a simple test, it fails when the message. "An internal error occurred while launching test executor for Windows Metro Style app". Disabling the property listed above makes it so the test can run, but I can't reference any WinRT namespaces or components...

    What am I doing wrong?


    PS - I know this is possible, because I've done it before. I just don't remember what I did... in fact I don't remember having to do anything in order for it to work.


    • Edited by JSAndrew Wednesday, April 25, 2012 8:40 PM
    Wednesday, April 25, 2012 4:58 PM

Answers

  • Hi Andrew,

    There are different templates for native test library for desktop and Metro style.

    For testing native WinRT Component DLL, please create test library project from "New Project" -> "C++" -> "Windows Metro style" -> "Unit Test Library". This project template has all required properties and resources. You should be able to add WinRT code and take reference of WinRT component DLL.

    - Vikram

    • Marked as answer by JSAndrew Friday, April 27, 2012 10:14 PM
    Thursday, April 26, 2012 4:34 AM

All replies

  • Hi Andrew,

    There are different templates for native test library for desktop and Metro style.

    For testing native WinRT Component DLL, please create test library project from "New Project" -> "C++" -> "Windows Metro style" -> "Unit Test Library". This project template has all required properties and resources. You should be able to add WinRT code and take reference of WinRT component DLL.

    - Vikram

    • Marked as answer by JSAndrew Friday, April 27, 2012 10:14 PM
    Thursday, April 26, 2012 4:34 AM
  • Hello Andrew,

    Can you please share whether you are using a metro style unit test project or a unit test project (which is non-metro)? If non-metro, then can you please try with metro style unit test project and see whether it works for you or not?

    Regards

    Aseem Bansal

    Thursday, April 26, 2012 4:38 AM
  • Yes, this was indeed the issue. It's a bit confusing how there are multiple C++ unit testing project types, all nested under WinRT. I'm sure I won't be the last person to make this same mistake.
    Friday, April 27, 2012 10:14 PM
  • Thanks for feedback Andrew. Same template names do create confusion specially for first time. We are considering making small change in names to make differentiation clear in future builds.

    Regards, Vikram Agrawal, Developer, VSTLM, Microsoft Corporation

    Saturday, April 28, 2012 1:39 AM
  • Hi Vikram, I wonder whether we could get code coverage using metro style test library as I am developing a metro app and have followed the steps in MSDN to create related UT. Now the UT works well but I can't get code coverage info.

    Best Wishes,

    Dollar


    dollar zhang

    Saturday, May 26, 2012 1:23 PM
  • Hi Dollar,

    Currently code coverage is not supported with unit test for Metro style apps / library.


    Regards,
    Vikram Agrawal,
    Developer, VSTLM, Microsoft Corporation

    Sunday, May 27, 2012 6:25 AM
  • Hi Vikram,

    Thanks for your quick response.

    Another question: Code coverage is not support in VS11 beta currently, will it be supported in later version?


    dollar zhang

    Sunday, May 27, 2012 8:07 AM