Theory methods should use all of their parameters
This rule is triggered by having an unused parameter on your [Theory]
.
Unused parameters are typically an indication of some kind of coding error (typically a parameter that was previously used and is no longer required, or a parameter that was overlooked in the test implementation).
To fix a violation of this rule, you may:
using Xunit;
static class MyGreetingService
{
public static string Greet(string name) =>
$"Hello, {name}!";
}
public class xUnit1026
{
[Theory]
[InlineData("Joe", 42)]
public void ValidateGreeting(string name, int age)
{
var result = MyGreetingService.Greet(name);
Assert.Equal("Hello, Joe!", result);
}
}
using Xunit;
static class MyGreetingService
{
public static string Greet(string name) =>
$"Hello, {name}!";
}
public class xUnit1026
{
[Theory]
[InlineData("Joe", 42)]
public void ValidateGreeting(string name)
{
var result = MyGreetingService.Greet(name);
Assert.Equal("Hello, Joe!", result);
}
}
using Xunit;
static class MyGreetingService
{
public static string Greet(string name, int age) =>
$"Hello, {name}! How do you like being {age} years old?";
}
public class xUnit1026
{
[Theory]
[InlineData("Joe", 42)]
public void ValidateGreeting(string name, int age)
{
var result = MyGreetingService.Greet(name, age);
Assert.Equal("Hello, Joe! How do you like being 42 years old?", result);
}
}