ERROR: Async test method must have non-void return type in Asp.Net Core

Dung Do Tien Feb 17 2021 63

Hello,

I'm trying to work with async in Asp.Net Core 3.1.  And I write a method for a unit test as below:

 [TestCase("mercedes-benz")]
public async void GetKeywordOnPageForSaleByBrand(string brandAlias)
{
    var listKeywordCount = await _serviceProvider.GetService<IKeywordService>().GetKeywordOnPageForSaleByBrand(brandAlias);
    Assert.IsNotNull(listKeywordCount);
}

But this test case is failed and throw a message error Async test method must have non-void return type.

Please tell me why if you know any reason!

Have 1 answer(s) found.
  • Asynchronous not allow void data type for a method. Please change void keyword to Task in your method

     public async void GetKeywordOnPageForSaleByBrand(string brandAlias)
    
    TO 
    
    public async Task GetKeywordOnPageForSaleByBrand(string brandAlias) 
    PTJ312 Feb 17 2021
Leave An Answer
* NOTE: You need Login before leave an answer

* Type maximum 2000 characters.

* All comments have to wait approved before display.

* Please polite comment and respect questions and answers of others.

Popular Tips

X Close