Passing a custom type object as a parameter

瀏覽次數:7,262 次
跳到第一則未讀訊息

Sandbox

未讀,
2010年8月1日 凌晨3:30:232010/8/1
收件者: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

未讀,
2010年8月1日 上午9:38:032010/8/1
收件者: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.
>
>

回覆所有人
回覆作者
轉寄
0 則新訊息