locked
UITestMethod method not responding RRS feed

  • Question

  • I have a Windows store app unit test project created via VS 2013 template. I want to test whether the camera is working. In the following code, the Camera.CapturePicture() method will bring up the CameraCaptureUI(). If I make the call in a real winrt application, it works. But in the test project, there is no response from the method CameraCaptureUI.CaptureFileAsync() (this method is in Camera.CapturePicture() method). My understanding is that the UITestMethod will help to test UI. Am I missing anything in the test project?

    [TestClass]
    public class CameraInteraction
    {
        #region Public Methods and Operators
    
        [UITestMethod]
        public void CapturePicture_NoState_CheckImage()
        {
            var image = Camera.CapturePicture();
    
            Assert.IsNotNull(image.Result);
        }
    
        #endregion
    }


    Monday, May 12, 2014 10:10 AM

Answers

  • Hi,

    UITestMethod attribute is used to run unit tests for Windows Store Apps on the main UI thread.

    Generally we use CameraCaptureUI class  to take a picture like this:

    // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo

    CameraCaptureUI dialog = new CameraCaptureUI();

    Size aspectRatio = new Size(16, 9);

    dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;

    StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);

    So I assume that the CapturePicture() method is an async method. In this case the unit test method need to be set to async in order to test the async method. But async TestMethod with UITestMethodAttribute are not supported. We only can test async methods in unit test with TestMethod attribute like this: http://vunvulearadu.blogspot.com/2013/04/how-to-write-unit-tests-for-async.html

    So I suggest you use Coded UI test for the UI testing rather than unit test.

    Best regards,

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    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.


    Thursday, May 15, 2014 5:53 AM

All replies

  • You'll need to make sure the calls to UI code such as CaptureCameraUI run on the dispatcher thread. You can call Dispatcher.RunAsync to ,arshal a call over, but usually you'd use CodedUI for UI testing rather than Unit testing.

    The folks in the unit testing forum may be able to provide more detail.

    Monday, May 12, 2014 12:30 PM
  • I tried to run the static method Camera.CapturePicture in a dispatcher. I see the same result where there is no response. Should I run just the method CaptureCameraUI in the dispatcher?

    The documentation says [UITestMethod] can be used where the dispatcher needs to be used.


    Monday, May 12, 2014 8:44 PM
  • Hi,

    UITestMethod attribute is used to run unit tests for Windows Store Apps on the main UI thread.

    Generally we use CameraCaptureUI class  to take a picture like this:

    // Using Windows.Media.Capture.CameraCaptureUI API to capture a photo

    CameraCaptureUI dialog = new CameraCaptureUI();

    Size aspectRatio = new Size(16, 9);

    dialog.PhotoSettings.CroppedAspectRatio = aspectRatio;

    StorageFile file = await dialog.CaptureFileAsync(CameraCaptureUIMode.Photo);

    So I assume that the CapturePicture() method is an async method. In this case the unit test method need to be set to async in order to test the async method. But async TestMethod with UITestMethodAttribute are not supported. We only can test async methods in unit test with TestMethod attribute like this: http://vunvulearadu.blogspot.com/2013/04/how-to-write-unit-tests-for-async.html

    So I suggest you use Coded UI test for the UI testing rather than unit test.

    Best regards,

    Note: This response contains a reference to a third party World Wide Web site. Microsoft is providing this information as a convenience to you. Microsoft does not control these sites and has not tested any software or information found on these sites; therefore, Microsoft cannot make any representations regarding the quality, safety, or suitability of any software or information found there. There are inherent dangers in the use of any software found on the Internet, and Microsoft cautions you to make sure that you completely understand the risk before retrieving any software from the Internet.


    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.


    Thursday, May 15, 2014 5:53 AM