unit testing asynchronous operation

前端 未结 4 562
名媛妹妹
名媛妹妹 2021-02-13 11:41

I want to unit test a method that I have that performs and async operation:

 Task.Factory.StartNew(() =>
        {
            // method to test and return v         


        
4条回答
  •  醉梦人生
    2021-02-13 12:40

    Try something like this...

    object result = null;
    Task t =  Task.Factory.StartNew(() => result = LongRunningThing()); 
    
    
    Task.Factory.ContinueWhenAll(new Task[] { t }, () => 
    {
       Debug.Assert(result != null);
    });
    

提交回复
热议问题