我是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");
});
}
答案 0 :(得分:5)
使测试异步
[TestMethod]
public async Task TestGet() {
var foo = new Foo();
var result = await foo.GetWebAsync();
Assert.IsNotNull(result, "error");
Console.Write(result);
}