【发布时间】:2013-02-08 02:16:46
【问题描述】:
我是单元测试的新手,我正在尝试为使用任务的 WPF ViewModel 编写单元测试。我在 VM 中有一个方法,它连接到 WPF 中的按钮。下面的代码总结了我正在尝试做的事情。 类 MainPageViewModel { 私有 IService 服务_;
public void StartTask()
{
var task = service_.StartServiceAsync();
task.ContinueWith(AfterService);
}
private void AfterService(Task<IResult> result)
{
//update UI with result
}
}
class TestClass
{
[TestMethod]
public Test_StartTask()
{
MainPageViewModel vm = new MainPageViewModel();
vm.StartTask();
//need to check if UI is updated but since the AfterService is called on a different thread the assert fails
}
}
在我的测试方法中,我无法在 StartTask() 调用后编写 Assert,请帮助我了解如何处理此类情况? TIA。
【问题讨论】:
-
您真正想要测试的内容。通过查看代码,我看不到您尝试进行单元测试的任何重要行为。
标签: .net unit-testing c#-4.0 task