TestCaseProviders (NUnit 2.5)

Purpose

TestCaseProviders are used with parameterized tests to provide the specific test cases that will be used in calling the test.

Extension Point

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

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

Interface

The extension object passed to Install must implement either the ITestCaseProvider or the ITestCaseProvider2 interface:

	public interface ITestCaseProvider
	{
		bool HasTestCasesFor( MethodInfo method );
		IEnumerable GetTestCasesFor( MethodInfo method );
	}
	
	public interface ITestCaseProvider2 : ITestCaseProvider
	{
		bool HasTestCasesFor( MethodInfo method, Test suite );
		IEnumerable GetTestCasesFor( MethodInfo method, Test suite );
	}

NUnit will call ITestCaseProvider2 if it is available. Otherwise ITestCaseProvider will be used.

HasTestCasesFor should return true if the provider is able to supply test cases for the specified method. If a provider only wants to be used on certain types of tests, it can examine the provided MethodInfo and the suite for which the test is being constructed and return true or false based on what it finds.

The GetParametersFor method should return a list of individual test cases. Each test case may be expressed as a ParameterSet, as an array of arguments or as a custom object containing one or more of the following properties:

The ParameterSet class provides all these properties and may be used to avoid the overhead of reflecting on the properties.

Notes:

  1. Most providers will delegate one of the interface implementations to the other if they implement both.
  2. TestCaseProviders that use data from the fixture class should use ITestCaseProvider2 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 ITestCaseProvider alone.
  4. The ITestCaseProvider2 interface was added in the NUnit 2.5.1 release.