ReSharper 2024.1 Help

Code inspection: NUnit. Test case source must be field, property, or method.

Category

NUnit

ID

NUnit.TestCaseSourceMustBeFieldPropertyMethod

EditorConfig

resharper_n_unit_test_case_source_must_be_field_property_method_highlighting

Default severity

Warning

Language

C#

Requires SWA

No

NUnit's TestCaseSource and ValueSource attributes require data source members to be static field, property, or method.

[TestFixture] public sealed class TestCaseSourceTest { static IEnumerable<int> _fieldSource = new[] {1, 2, 3}; static IEnumerable<int> PropertySource => new[] {4, 5, 6}; static IEnumerable<int> MethodSource() => new[] {7, 8, 9}; public event UnhandledExceptionEventHandler OnError { add => throw new NotImplementedException(); remove => throw new NotImplementedException(); } [TestCaseSource(nameof(_fieldSource))] // ok [TestCaseSource(nameof(PropertySource))] // ok [TestCaseSource(nameof(MethodSource))] // ok [TestCaseSource(nameof(OnError))] // Warning: expected field/property/method public void Test1(int x) { Console.WriteLine(x); } }
Last modified: 11 February 2024