[英]unit testing async task in csharp
我是visual studio / c#中的單元測試和異步操作的新手。 感謝任何幫助。
我的主要課程
class Foo
{
public async Task<string> GetWebAsync()
{
using (var client = new HttpClient())
{
var response = await client.GetAsync("https://hotmail.com");
return await response.Content.ReadAsStringAsync();
}
}
}
單元測試
[TestMethod]
public void TestGet()
{
Foo foo = new Foo();
foo.GetWebAsync().ContinueWith((k) =>
{
Console.Write(k);
Assert.IsNotNull(null, "error");
});
}
也使測試異步
[TestMethod]
public async Task TestGet() {
var foo = new Foo();
var result = await foo.GetWebAsync();
Assert.IsNotNull(result, "error");
Console.Write(result);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.