NSubstitute.Analyzers
NSubstitute.Analyzers copied to clipboard
Analyzer for misuse of `Arg.Any<T>` in xunits `Asert.Throws<T>`?
Is there already an analyzer that schould trigger when the following incorrect use happens? This caused some isssues in my test library and I only found out after commenting out about 50 tests. So an analyzer would be great for that kind of scenario.
using System;
using NSubstitute;
using Xunit;
namespace Tests;
public interface IMyInterface
{
int MyMethod(string myParameter);
}
public class TestClass
{
[Fact]
public void IStItem_GetNext_ShouldThrow()
{
// Arrange
var substitute = Substitute.For<IMyInterface>();
// Act/Assert
Assert.Throws<NotImplementedException>(() => substitute.MyMethod(Arg.Any<string>())); // <-- INcorrect | should trigger
Assert.Throws<NotImplementedException>(() => substitute.MyMethod(string.Empty)); // <-- correct | should NOT trigger
}
}