Legacy Documentation. View NUnit 3 Documentation

DataPointProviders (NUnit 2.5)

Purpose

DataPointProviders are used to supply data for an individual parameter of a parameterized test method.

Extension Point

Addins use the host to access this extension point by name:

	IExtensionPoint listeners = host.GetExtensionPoint( "DataPointProviders" );

Interface

The extension object passed to Install must implement either the IDataPointProvider or the IDataPointProvider2 interface:

	public interface IDataPointProvider
	{
		bool HasDataFor( ParameterInfo parameter );
		IEnumerable GetDataFor( ParameterInfo parameter );
	}

	public interface IDataPointProvider2 : IDatapointProvider
	{
		bool HasDataFor( ParameterInfo parameter, Test parentSuite );
		IEnumerable GetDataFor( ParameterInfo parameter, Test parentSuite );
	}

NUnit will call IDataPointProvider2 if it is available. Otherwise IDataPointProvider will be used.

The HasDataFor method should return true if the provider is able to supply data for the specified parameter. If a provider only wants to be used on certain types of tests, it can examine the supplied ParameterInfo and its associated MethodInfo and Type and/or the parent test suite.

The GetDataFor method should return a list of individual values to use for the supplied parameter in running the test.

Notes:

  1. Most providers will delegate one of the interface implementations to the other if they implement both.
  2. DataPointProviders that use data from the fixture class should use IDataPointProvider2 interface so that they are able to access any arguments supplied for constructing the fixture object.
  3. Providers that acquire data from outside the fixture will usually be able to work with IDataPointProvider alone.
  4. The IDataPointProvider2 interface was added in the NUnit 2.5.1 release.