locked
[UWP][Unit Test] COMException^ thrown when I reference a Windows::UI::ViewManagement from Universal APp Library RRS feed

  • Question

  • Here is the setup I used to reproduce my issue:

    1. Create a UWP Library with the one call as follows:

      using namespace Windows::UI::ViewManagement;
      void noop() {
        auto bounds = ApplicationView::GetForCurrentView()->VisibleBounds;
      }
      

      This function uses the ApplicationView to get the screen bounds of the current app instance.

    2. Create another UWP Test App which references the library. Within it's test method, I call the noop() from MyLib.

    On running the tests, it fails and throws a Platform::COMException^. Is there something I am missing?

    Thanks for your time.

    Wednesday, May 17, 2017 9:35 AM

All replies

  • Here is the setup I used to reproduce my issue:

    1. Create a UWP Library with the one call as follows:

      using namespace Windows::UI::ViewManagement;
      void noop() {
        auto bounds = ApplicationView::GetForCurrentView()->VisibleBounds;
      }
      

      This function uses the ApplicationView to get the screen bounds of the current app instance.

    2. Create another UWP Test App which references the library. Within it's test method, I call the noop() from MyLib.

    On running the tests, it fails and throws a Platform::COMException^. Is there something I am missing?

    Thanks for your time.

    Wednesday, May 17, 2017 9:34 AM
  • I assume that your Test App doesn't run in a UI context and so doesn't have a current view. Your function assumes that ApplicationView::GetForCurrentView always returns a view. This is not a safe assumption if you don't control the calling context.

    Folks in the Unit Testing forum should be able to confirm.

    Wednesday, May 17, 2017 8:49 PM
  • Thanks. It seems correct that I need to have some way to run test on UI thread as well. I expected this from the UT framework itself, but am unable to find anything there. I have reposted this onto Unit Testing Forum as well. I will wait for someone there to respond.

    Thursday, May 18, 2017 5:22 AM
  • Hi friend,

    Have you used the [UITestMethod] attribute above the test method?

    If not please try it and add the:

    using Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer;

    at the top.

    Best regards,

    Fletch


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Monday, May 22, 2017 9:24 AM
  • @Fletch: I am using C++/CX to develop my app and there does not seem to be a namespace TestTools within Microsoft::VisualStudio.

    Is this functionality not available in UWP with C++/CX? Is there a definitive documentation around this in that case? 

    Thanks,

    A


    Tuesday, May 23, 2017 8:48 AM
  • Hi friend,

    Sorry about the misunderstanding. There is no UIMethod attribute definition in C++, it only exist in C#:

    https://blogs.msdn.microsoft.com/visualstudioalm/2013/02/02/improvements-in-windows-store-unit-tests-test-exceptions-in-async-lambda-expressions-run-tests-on-the-ui-thread/

    As you are using C++, please refer to UIElement in C++/CX, you may get some useful information here:

    https://docs.microsoft.com/en-us/uwp/api/windows.ui.xaml.uielement

    Best regards,

    Fletch 


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.


    Friday, May 26, 2017 10:21 AM