6

I have basic question about Data Driven Tests.

I tried something like

[TestMethod]
[DataRow(new DateTime(2018,10,25))]     
public void SpecialDateOperation(DateTime date)
{
    // test...
}

But I am getting an error

An attribute argument must be a constant expression, typeof expression or array creation expression of an attribute parameter type

Somehow I am not able to get it to work. What is the issue here?

Nkosi
  • 235,767
  • 35
  • 427
  • 472
Muflix
  • 6,192
  • 17
  • 77
  • 153
  • 3
    Pass a string and parse it in the test method. The first phrase of the exception spell it out for you as you are trying to initialize an object in the attribute, not pass a constant value. – Nkosi Oct 25 '18 at 14:13
  • DataRow is not very helpful here... I would have a TestMethod construct some kind of list of tuple with in your case DateTime and perhaps the expected value; then iterate on that list and call a second method that does the Act and Assert part. – Jocke Oct 25 '18 at 18:28
  • 6
    This isn't a duplicate of the references issue. The referenced issue is about DataTestMethods in general. This one is specific for datetime values. – Julian Nov 05 '19 at 10:07
  • Any other solution to get this working? – Enrico Aug 21 '20 at 12:06

0 Answers0