How to add capabilities to Coded UI Test (Windows Phone 8.1) project (In C#)

两盒软妹~` 提交于 2019-12-07 05:59:41

问题


I've a TestMethod in CodedUITest class that uses HttpClient for fetching data from a local server,

[TestMethod]
public void CodedUITestMethod()
{
string ServiceURI = "http://localhost:34562/GetTestResult";
HttpClient httpClient = new HttpClient();
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Get, ServiceURI);
HttpResponseMessage response = httpClient.SendAsync(request).Result;
}

However, it always throws exception at last line, like:

{System.UnauthorizedAccessException: Use of networking APIs requires the ID_CAP_NETWORKING capability to be defined in the application manifest.
   at MS.Internal.Modern.ClientHttpWebRequestCreator.Create(Uri uri)
   at System.Net.WebRequest.Create(Uri requestUri, Boolean schemeOnly)
   at System.Net.WebRequest.Create(Uri requestUri)
   at System.Net.Http.HttpClientHandler.CreateAndPrepareWebRequest(HttpRequestMessage request)
   at System.Net.Http.HttpClientHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)}

Based on Required Manifest Capabilities It seems there's no way for a Coded UI project to specify app manifest.

Does anyone have any idea how to specify ID_CAP_NETWORKING capability?


回答1:


It seems like you're trying to UI test the response you get from the server (correct me if I'm wrong). Coded UI Testing is not intended for this usage.

When it comes to testing you have (more but usually) two methods of going about it:

  • Unit Testing

With Unit Testing you aim to test small portions of your code (classes/methods) isolated from the real world implementation of your application. I.e. Check if your Get method returns correct HTTP response codes in different situations.

  • UI Testing

Generally something you do as part of functional / acceptance test. You ensure the application behaves as it should during real world implementation. I.e. Checking if a button correctly sets a value in a textbox.

What you're trying to do (again, correct me if I'm wrong) is combining both to do a real world implementation and test certain methods of your webservice. The Coded UI framework expects an application under test to run against, if you're only using Get methods to check if you get back the correct data, or in the right format I'd suggest you try out unit testing.

You can read more about unit testing here.



来源:https://stackoverflow.com/questions/30211128/how-to-add-capabilities-to-coded-ui-test-windows-phone-8-1-project-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!