Jump to content
Sign in to follow this  
Uwe Raabe

What is the reason for this code in TTestDataProvider.GetProvider?

Recommended Posts

The current implementation of one overload of TTestDataProvider.GetProvider looks like this:

class function TestDataProviderManager.GetProvider(const AClass: TTestDataProviderClass) : ITestDataProvider;
var
  key : string;
begin
  result := nil;
  if (FList.ContainsValue(AClass)) then
  begin
    for key in flist.keys do
    begin
      if (flist[key] = AClass) then
      begin
        result := TTestDataProviderClass(flist[key]).Create;
        break;
      end;
    end;
  end;
end;

Is there any reason why that cannot be written as:

class function TestDataProviderManager.GetProvider(const AClass: TTestDataProviderClass) : ITestDataProvider;
begin
  result := AClass.Create;
end;

With that one could avoid registering the provider.

 

The reasoning for my question is, that I have a base provider class and several derived classes to overcome the lack of ability to parametrize a data provider instance. All these derived classes are local to one test unit and I would like all of them to have the same class name. Unfortunately the registration requires me to give distinct names for them and you know - naming is hard. Just declaring the derived class and use that in a TestCaseProvider attribute would simplify this a lot.

 

Concrete: TTestDataFilesProvider provides a list of files, but requires the path and search pattern as parameters. Now I derive individual classes (with fixed values) immediately before they are used.

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  
×