0

I guess the best practice in unit testing is writing code always called (like create object , do a primary init of these objects, .... ) for a test inside the setup procedure

  [TestFixture]
  TMY_Testcases = class
  private

    FTestConfigParameter: TParameter;


  public

    [Setup]
    procedure Setup;
    [TearDown]
    procedure TearDown;

    [Test]
    [TestCase('CreateTrue', 'True')]
    [TestCase('CreateFalse', 'False')]
    procedure Test_DoMyTest (Createflag : Boolean);

  end; 

I have several sets of parameters for my objects I do the object.create in the setup procedure. Is there any way to run the test cases with the setup procedure getting my parameter? My ugl solution goes like this :

    [Setup]
    procedure Setup;
    [TearDown]
    procedure TearDown;
    
    procedure MySetup(MyParameter : TParameter);

    [TestCase('CreateWithParameter', 'False,Parameter_AsString')]
     procedure Test_DoMyTest (Createflag : Boolean, Parameter : TParameter);

This approach makes setup and Teardown procedure obsolete, any better approach?

Franz
  • 1,883
  • 26
  • 47

1 Answers1

1

The attribute Setup obviously has no parameters of its own. If these parameters should be filled by the test, then every test should have those parameters too? Or how should that work?

The idea behind the Setup attribute is to set things up for your test that work that way for all tests in your Fixture. Otherwise, it's a setup that belongs specifically to your test and then you get a solution like you've already figured out yourself in my opinion.

procedure TMY_Testcases.Test_DoMyTest (Createflag : Boolean, Parameter : TParameter);
begin
  MySetup(Parameter);

  // Test here...
end;