Skip to content

Commit

Permalink
修复在单元测试过程退出应用,单元测试将等待单元测试执行结果不会退出
Browse files Browse the repository at this point in the history
单元测试的执行结果在等待 UI 线程调度,但是 UI 线程已经退出,不会再调度
  • Loading branch information
lindexi committed Oct 26, 2022
1 parent 87de9d4 commit 506c44a
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/dotnetCampus.UITest.WPF/UITestMethodProxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,12 @@ private protected override TestResult InvokeCore(ITestCase testCase)
{
var task = Application.Current.Dispatcher.Invoke(async () =>
{
return await contractTestCase.ExecuteAsync();
var result = await contractTestCase.ExecuteAsync()
// 如果在执行过程,应用退出了,那在没有加上 ConfigureAwait 设置为 false 那将需要调度回 UI 线程,才能返回
// 由于应用退出了,也就是 UI 线程不会调度的任务
// 因此不会返回,单元测试将会卡住
.ConfigureAwait(false);
return result;
});

return task.Result;
Expand Down

0 comments on commit 506c44a

Please sign in to comment.