Skip to content

Instantly share code, notes, and snippets.

@bradwilson
Created March 15, 2026 22:57
Show Gist options
  • Select an option

  • Save bradwilson/c8def267357285136024d2ef7c3fd885 to your computer and use it in GitHub Desktop.

Select an option

Save bradwilson/c8def267357285136024d2ef7c3fd885 to your computer and use it in GitHub Desktop.
Showing a single large test instead of multiple small tests
[Fact]
public async Task v2_and_v3()
{
var source = /* lang=c#-test */ """
using System.Runtime.InteropServices;
using Xunit;
public class TestClass {
[Theory]
[InlineData("abc", 1, null)]
public void MethodWithImplicitParameters(string a, int b, object c) { }
[Theory]
[InlineData(new object[] { "abc", 1, null })]
public void MethodWithExplicitParameters(string a, int b, object c) { }
[Theory]
[InlineData(data: new object[] { "abc", 1, null })]
public void MethodWithExplicitParameters_Named(string a, int b, object c) { }
[Theory]
[InlineData(new byte[0])]
public void MethodWithEmptyArray(byte[] input) { }
// https://github.com/xunit/xunit/issues/3000
[Theory]
[InlineData({|CS0182:0.1m|})]
public void MethodWithDecimalValue(decimal m)
{ }
// Optional parameters
[Theory]
[InlineData("abc")]
[InlineData("abc", "def")]
[InlineData("abc", "def", "ghi")]
public void MethodWithDefaultParameterValues(string a, string b = "default", string c = null) { }
[Theory]
[InlineData]
[InlineData("abc")]
[InlineData("abc", "def")]
public void MethodWithOptionalAttribute([Optional] string a, [Optional] string b) { }
// Params parameter
[Theory]
[InlineData("abc", "xyz")]
public void MethodWithImplicitParams(params string[] args) { }
[Theory]
[InlineData(new object[] { new string[] { "abc", "xyz" } })]
public void MethodWithExplicitParams(params string[] args) { }
[Theory]
[InlineData]
public void MethodWithImplicitEmptyParams(params string[] args) { }
[Theory]
[InlineData(new object[] { new string[0] })]
public void MethodWithExplicitEmptyParams(params string[] args) { }
[Theory]
[InlineData(null)]
public void MethodWithNullParams(params string[] args) { }
[Theory]
[InlineData("abc", "xyz")]
public void MethodWithMixedNormalAndImplicitParams(string first, params string[] args) { }
[Theory]
[InlineData("abc", new[] { "xyz" })]
public void MethodWithMixedNormalAndExplicitParams(string first, params string[] args) { }
[Theory]
[InlineData("abc")]
public void MethodWithMixedNormalAndImplicitEmptyParams(string first, params string[] args) { }
[Theory]
[InlineData("abc", new string[] { })]
public void MethodWithMixedNormalAndExplicitEmptyParams(string first, params string[] args) { }
[Theory]
[InlineData("abc", null)]
public void MethodWithMixedNormalAndNullParams(string first, params string[] args) { }
// Mixed optional and params parameters
[Theory]
[InlineData("abc")]
public void MethodWithOptionalParametersWithDefaultValuesAndParamsParameter(string a, string b = "default", string c = null, params string[] d) { }
}
#nullable enable
public class NullableTestClass {
[Theory]
[InlineData("abc", 1, null)]
public void MethodWithImplicitParameters(string a, int b, object? c) { }
[Theory]
[InlineData(new object[] { "abc", 1, null })]
public void MethodWithExplicitParameters(string a, int b, object? c) { }
[Theory]
[InlineData(data: new object[] { "abc", 1, null })]
public void MethodWithExplicitParameters_Named(string a, int b, object? c) { }
// Optional parameters
[Theory]
[InlineData("abc")]
[InlineData("abc", "def")]
[InlineData("abc", "def", "ghi")]
public void MethodWithDefaultParameterValues(string a, string b = "default", string? c = null) { }
[Theory]
[InlineData]
[InlineData("abc")]
[InlineData("abc", "def")]
public void MethodWithOptionalAttribute([Optional] string? a, [Optional] string? b) { }
// Params parameter
[Theory]
[InlineData(null)]
public void MethodWithNullParams(params string[]? args) { }
[Theory]
[InlineData("abc", null)]
public void MethodWithMixedNormalAndNullParams(string first, params string[]? args) { }
// Mixed optional and params parameters
[Theory]
[InlineData("abc")]
public void MethodWithOptionalParametersWithDefaultValuesAndParamsParameter(string a, string b = "default", string? c = null, params string[] d) { }
}
""";
await Verify.VerifyAnalyzer(LanguageVersion.CSharp8, source);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment