I want to test using xunit a function that run a task and throw in a that task For example :
public void doSomething(){
Task.Run(() =>
{
throw new ArgumentNullException();
});
}
When I want to test this function by doing this :
[Fact]
public void TestIfTheMethodThrow()
{
Assert.Throws<ArgumentNullException>(() => doSomething()); // should return true but return false
}
I want that the Task.Run() finish completely then the assert can be done. anyone have a solution ?