DataSourceAttribute (NUnit 2.5)
Preliminary documentation, subject to change.
DataSourceAttribute is used on individual parameters of a test method to identify the source from which arguments will be suppoied. The attribute has four public constructors.
DataSourceAttribute(Type sourceType, string name1,
params string[] moreNames);
DataSourceAttribute(string name1, params string[] moreNames);
// For CLS-Compliance
FactoriesAttribute(Type sourceType, string sourceName);
FactoriesAttribute(string sourceName);
If sourceType is specified, it represents the class that provides the data. If not, the class containing the test method is used.
Each sourceName, represents the name of a field, property or method that will provide the arguments.
Each individually named source has the following characteristics:
- It may be a field, property or method.
- It may be either an instance or a static member.
- It must be an IEnumerable or a type that implements IEnumerable.
NUnit locates the data sources at the time the tests are loaded, creates instances of each class having non-static sources and builds a list of tests to be executed. Each instancet is only created once at this time and is destroyed after all tests are loaded. In the case of sources located within the same class as the tests, a different instance is created each time the test is run, so no communication is possible using non-static members of the class.
