Loading...

nunit-discuss@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

RE: [nunit-discuss] Recommended way to initialize Datapoint instance variables Charlie Poole Wed Dec 30 22:00:03 2009

Hi, 

> When doing theory testing using the Theory attribute and 
> Datapoint/ Datapoints attributes, what is the recommended way 
> to initialize more advanced variables used as Datapoints? If 
> you are initializing a complex object, or a collection of 
> complex objects, or an array of a collection of complex 
> objects, it is inconvenient and sometimes impossible to do 
> all the initialization where these instance variables are 
> declared. I discovered that you can do initialization in the 
> constructor of the TestFixture class, but this is not 
> preferable for me because when running single tests or single 
> test fixtures to check the code coverage, other unrelated 
> TestFixture classes are also constructed. That is a problem 
> because it causes the code coverage reports to show hits from 
> code that is not even being tested. Any related commendations 
> that do not directly answer my question are also appreciated.

For complex objects such as you describe, I would probably not
use Datapoint/Datapoints. Theories can take data from any of
the other data sources defined in NUnit in addition to using
Datapoints. In this case, I would probably use a TestCaseSource
attribute pointing to a method of either the fixture class or
a separate class. The method can be static or instance. If it's
static, no 'extra' constructions take place. It will be called
once for each test that uses the source and you can either 
return the same data each time or fresh data.

As I mentionned on your bug report, I'm not clear what you 
mean by "unrelated" TestFixture classes being constructed.

Charlie

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



--

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