TestCaseData attribute not doing automatic conversion from double to decimal

131 views
Skip to first unread message

Morten Grøtan

unread,
Aug 9, 2011, 9:40:12 AM8/9/11
to NUnit-Discuss
Hi,
I'm aware of the nifty feature of supplying constants of type double
to test methods expecting decimal input, to workaround the C#
attribute limitation.

The same is not true when using TestCaseSource/TestCaseData. Then the
dreaded "An attribute argument must be a constant expression, typeof
expression or array creation expression of an attribute parameter
type" error occurs, not at compile time, but at runtime.

For now, I've converted my TestCaseSource instances to TestCase
attributes instead, but I'd prefer to have them separated away in
their own classes/source files to avoid all the clutter.

Charlie Poole

unread,
Aug 9, 2011, 10:44:50 AM8/9/11
to nunit-...@googlegroups.com
Hi Morten,

When I implemented the special conversions for TestCaseAttribute, I wanted
to be careful that I was not performing conversions too agressively. So I tried
to implement the minimal set needed to use common argument types.

For the same reason, I didn't promulgate these conversions to other sources
of test case data, which don't rely on attribute arguments. I felt that it would
be confusing to the experienced C# developer if non-standard conversions
were automatically applied in those cases.

A further reason for wanting to make TestCaseAttribute particularly easy to use
is that I personally believe it's the best choice when doing TDD, because the
data is immediately visible.

All that said, I'm willing to consider adding other conversions if folks in this
group agree with the idea.

One thing confuses me: why aren't you simply using decimal data directly
in your TestCaseSource data? An example might help clarify this.

Charlie

> --
> You received this message because you are subscribed to the Google Groups "NUnit-Discuss" group.
> To post to this group, send email to nunit-...@googlegroups.com.
> To unsubscribe from this group, send email to nunit-discus...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/nunit-discuss?hl=en.
>
>

Reply all
Reply to author
Forward
0 new messages