FP: Add some tests to this class

Hi,

we are seeing a FP report in one of our test classes. the C# scanner does not seem to recognize the DataTestMethod attribute.

using Microsoft.VisualStudio.TestTools.UnitTesting;
using ***.ValueConverters;

namespace ***.Client.Test.ValueConverters
{
    [TestClass]
    public class NumericComparisonToBoolConverterTest
    {
        /// <summary>
        /// Test Class for <see cref="NumericComparisonToBoolConverter"/> class
        /// </summary>
        [TestClass]
        public class ZeroToTrueBooleanConverterTest
        {
            [DataTestMethod]
            [DataRow("I'm not zero")]  // String
            [DataRow(null)]  // null
            [DataRow(-1)]  // Lesser
            [DataRow(0)]  // Equal
            [DataRow(1)]  // Greater
            public void NoneReturnsFalse(object objectInQuestion)
            {
                //arrange

                //act
                var converter = new NumericComparisonToBoolConverter
                {
                    ComparisonNumber = 0,
                    ComparisonType = NumericComparisonToBoolConverter.NumericComparisonType.None
                };
                var result = converter.Convert(objectInQuestion, null, null, null);

                //assert
                Assert.IsTrue(result is bool);
                Assert.IsFalse((bool)result);
            }
        }
    }
}

The above code presents us with the following code smell.

My suggestion is to treat DataTestMethod just the way you treat TestMethod.

Best regards
Norbert

Hello @norberth

Thank you for taking the time to report this!

We have a test case with DataTestMethod and it seems to be supported from our side.

I cannot repro. Could you please give more details about your setup?

  • what is the version of Scanner for NET you are using?
  • what version of MSTest / Microsoft.NET.Test.Sdk are you using?
  • what is the version of MSBuild you are using?

Hi @Andrei_Epure ,

my mistake - I didn’t realize that the above code has a nested test class :frowning:
The outer class indeed does not have any tests.

We can consider this closed…

Best regards
Norbert

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.