我在 Windows 8 Release Preview 上使用 Visual Studio Express 2012,但似乎无法让我的单元测试出现在测试资源管理器中。
我有一个名为 TestApp.Entity 和 TestApp.EntityTest 的类...
这是我的代码:
namespace TestApp.Entity.Test
{
using System;
using System.Net.Http;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using TestApp.Domain;
[TestClass]
public class EntityTests
{
[TestMethod]
public async void TestObject1Deserialize()
{
Uri agencyUri = new Uri("*removed*");
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync(agencyUri);
string responseBodyAsText = await response.Content.ReadAsStringAsync();
List<Agency> agencyList = Deserializers.AgencyDeserialize(responseBodyAsText);
CollectionAssert.Contains(agencyList, new Agency() { Tag = "*removed*", Title = "*removed*", ShortTitle = "", RegionTitle = "*removed*" });
}
}
}
我认为这就是我需要做的所有事情,但它们仍然没有出现在测试资源管理器中。任何意见将是有益的。
最佳答案
根据 Stephen Cleary ,“您需要进行单元测试 async Task
而不是 async void
才能使它们正常工作”。
这解决了问题,测试出现了。奇怪的是,当我使用 void 时没有出现错误,但现在我知道了。谢谢!
关于unit-testing - 单元测试未出现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12614502/