JetBrains Rider 2025.2 Help

代码检查:NUnit。 测试用例来源必须是字段、属性或方法。

NUnit 的 TestCaseSourceValueSource属性要求数据源成员为静态 字段、属性或方法

[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); } }
最后修改日期: 2025年 9月 26日