Passing a custom type object as a parameter

7 252 wyświetlenia
Przejdź do pierwszej nieodczytanej wiadomości

Sandbox

nieprzeczytany,
1 sie 2010, 03:30:231.08.2010
do 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

nieprzeczytany,
1 sie 2010, 09:38:031.08.2010
do 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.
>
>

Odpowiedz wszystkim
Odpowiedz autorowi
Przekaż
Nowe wiadomości: 0