Passing a custom type object as a parameter

7,236 views
Skip to first unread message

Sandbox

unread,
Aug 1, 2010, 3:30:23 AM8/1/10
to NUnit-Discuss
I am using nunit 2.5.3.
I have used TestCase attribute with primitive types and enums. But, I
am not able to pass custom type object as parameter in TestCase.
Say, I have an Employee class
class Employee
{
public string Id{get;set;}
}

I have a test where in I want to pass different instances of Employee.
I have tried creating static objects, fields, creating and
initiliazing while passing as parameter in TestCase. None seems to
work. It gives a compile-time error. Am I missing something here? Is
it even possible to do this?

Thanks.

Charlie Poole

unread,
Aug 1, 2010, 9:38:03 AM8/1/10
to nunit-...@googlegroups.com
Using TestCaseAttribute, you are subject to C#s rules about what can be passed
in an attribute constructor.

* Attribute parameters are restricted to constant values of the
following types:
o Simple types (bool, byte, char, short, int, long, float, and double)
o string
o System.Type
o enums
o object (The argument to an attribute parameter of type
object must be a constant value of one of the above types.)
o One-dimensional arrays of any of the above types

That's why we have TestCaseSource, which allows you to create your cases
separately and just reference them by name.

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