Legacy Documentation. View NUnit 3 Documentation

DatapointAttribute / DatapointsAttribute (NUnit 2.5)

The Datapoint and Datapoints attributes are used to provide data for Theories and are ignored for ordinary tests - including tests with parameters.

DatapointAttribute

When a Theory is loaded, NUnit creates arguments for each of its parameters by using any fields of the same type as the parameter annotated with the DatapointAttribute. Fields must be members of the class containing the Theory and their Type must exactly match the argument for which data is being supplied.

DatapointsAttribute

In addition to specifying individual datapoints, collections of datapoints may be provided by use of the DatapointsAttribute - note the spelling. This attribute may be placed on methods or properties in addition to fields. The returned value must be either an array of the required type or (beginning with NUnit 2.5.5) an IEnumerable<T> returning an enumeration of the required type. The data Type must exactly match the argument for which data is being supplied.

Automatically Supplied Datapoints

It is normally not necessary to specify datapoints for boolean or enum arguments. Beginning with version 2.5.4, NUnit automatically supplies values of true and false for boolean arguments and will supply all defined values of any enumeration.

If for some reason you don't wish to use all possible values, you can override this behavior by supplying your own datapoints. If you supply any datapoints for an argument, automatic datapoint generation is suppressed.

Example

For an example of use, see TheoryAttribute.

See also...