site/xunit.analyzers/rules/xUnit2014.md
This rule is triggered when calling Assert.Throws with an async lambda.
Assert.Throws only supports non-async code.
To fix a violation of this rule, use Assert.ThrowsAsync (along with await).
using System;
using System.Threading.Tasks;
using Xunit;
public class xUnit2014
{
class MyMath
{
public static Task<int> Divide(params int[] values) => 42;
}
[Fact]
public void TestMethod()
{
Assert.Throws<DivideByZeroException>(() => MyMath.Divide(1, 0));
}
}
using System;
using System.Threading.Tasks;
using Xunit;
public class xUnit2014
{
class MyMath
{
public static Task<int> Divide(params int[] values) => 42;
}
[Fact]
public async void TestMethod()
{
await Assert.ThrowsAsync<DivideByZeroException>(() => MyMath.Divide(1, 0));
}
}