Skip to content

NUnit2007 shouldn't trigger for generic types e.g. typeof(T) #896

@mikkelbu

Description

@mikkelbu

I noticed the following error in the docs build of snippet (included below). We should not trigger on cases like this as the actual value is not a constant whereas the expected value is.

Image

https://github.com/nunit/docs/pull/1052/files?show-viewed-files=true&file-filters%5B%5D=#annotation_35790100039

    public class MyExplicitlyTypedTests
    {
        [TestCaseSource(nameof(ExplicitTypeArgsTestCases))]
        public void ExplicitTypeArgs<T>(T input)
        {
            Assert.That(typeof(T), Is.EqualTo(typeof(long)));
        }

        private static IEnumerable<TestCaseData> ExplicitTypeArgsTestCases()
        {
            yield return new TestCaseData(2) { TypeArgs = new[] { typeof(long) } };
            yield return new TestCaseData(2L) { TypeArgs = new[] { typeof(long) } };
        }
    }

Metadata

Metadata

Labels

No labels
No labels

Type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions