testfx icon indicating copy to clipboard operation
testfx copied to clipboard

Disallow test methods with out/ref parameters

Open Youssef1313 opened this issue 1 month ago • 1 comments

Today, the following is allowed:

        [TestMethod]
        [DataRow("Hello", "World")]
        public void TestMethod1(out string s, ref string s2)
        {
            s = "";
        }

I think we should:

  1. Fail at run time when we encounter such a test method.
  2. Update the analyzer for test method validity to also produce a compile-time warning.

It's technically a breaking change, but I think it's acceptable and is unlikely that people are doing this today.

Youssef1313 avatar Dec 05 '25 16:12 Youssef1313

If we want to be really safe, we could start by introducing the analyzer and wait for a few versions.

Evangelink avatar Dec 07 '25 06:12 Evangelink