Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TestCase parameters need sanitizing in XML log #60

Closed
LarsFosdal opened this issue Jun 4, 2014 · 1 comment
Closed

TestCase parameters need sanitizing in XML log #60

LarsFosdal opened this issue Jun 4, 2014 · 1 comment

Comments

@LarsFosdal
Copy link

Passing JSON as TestCase data will create humongous test names, which also will mess up the XML in the log.

Possible solutions

  1. Sanitize the params for XML inclusion. Test names will still look awful.
  2. Add flag(s) to an overloaded RegisterTestFixture to hide params in names
    Example:
    RegisterTDUnitX.RegisterTestFixture(TestTPSDTPack, [tfHideParams]);
    Suggesting a set of flags instead of explicit parameter, so that other flags can be added without breaking code.

See also Issue #59

SSCCE

program DUnitX_JSON_TestCase_Bug;

{$APPTYPE CONSOLE}
uses
  SysUtils,
  DUnitX.AutoDetect.Console,
  DUnitX.Loggers.Console,
  DUnitX.Loggers.Xml.NUnit,
  DUnitX.TestRunner,
  DUnitX.TestFramework;

const
  NoSep = '¤';

  NewTPack = String(
    '{"type":"PSDTPack.TPSDTPack","id":"0","fields":{"ReceptionOrderId":0,"ProductionOrderId":0,"TPackNo":"","ClientApplicationId":0,'
  + '"StoragePositionId":0,"LabeledExpirationDate":0,"LabeledArticleNo":"","BornDate":41756.4940430093,"LockState":1,"TPackStatus":0,'
  + '"TPackType":0,"AccessibleInStorage":0,"CarrierWeight":0,"LabeledWhen":0,"IsEmpty":1,"LastCountedDate":0,"SupplierId":0,'
  + '"SupplersGS1No":"703801","CustomerOrder_NFI":"","CarrierTypeId":0,"DeliveryId":0,"AllocatedDeliveryId":0,'
  + '"AllocatedToManufactOrderId":0},"listitems":[]}'
  );

 ChangedTPack = String(
    '{"type":"PSDTPack.TPSDTPack",'
//  + '"id":"0",'
  + '"fields":{"ReceptionOrderId":0,"ProductionOrderId":0,"TPackNo":"","ClientApplicationId":0,'
  + '"StoragePositionId":0,"LabeledExpirationDate":0,"LabeledArticleNo":"","BornDate":41756.4940430093,"LockState":1,"TPackStatus":0,'
  + '"TPackType":0,"AccessibleInStorage":0,"CarrierWeight":0,"LabeledWhen":0,"IsEmpty":1,"LastCountedDate":0,"SupplierId":0,'
  + '"SupplersGS1No":"703801","CustomerOrder_NFI":"","CarrierTypeId":0,"DeliveryId":0,"AllocatedDeliveryId":0,'
  + '"AllocatedToManufactOrderId":0},"listitems":[]}'
  );

  type

  [TestFixture]
  TestTPSDTPack= class
  public
    [Setup]
    procedure Setup;
    [TearDown]
    procedure TearDown;
    [Test]
    [TestCase('Create', NewTPack, NoSep)]
    procedure CreateFromJSON(const aJSON: String);
    [Test]
    function SaveToDB:Boolean;
    [Test]
    function ReadFromDb:Boolean;
    [Test]
    [TestCase('Modify', ChangedTPack, NoSep)]
    function ChangeAndSave(const aJSON: String):Boolean;
    [Test]
    function DeleteFromDb:Boolean;
  end;


{ TestTPSDCarrierType }

function TestTPSDTPack.ChangeAndSave(const aJSON: String): Boolean;
begin
  Assert.Fail('Something went wrong');
end;

procedure TestTPSDTPack.CreateFromJSON(const aJSON: String);
begin

end;

function TestTPSDTPack.DeleteFromDb: Boolean;
begin
  raise Exception.Create('That didn''t go as planned');
end;

function TestTPSDTPack.ReadFromDb: Boolean;
begin

end;

function TestTPSDTPack.SaveToDB: Boolean;
begin

end;

procedure TestTPSDTPack.Setup;
begin

end;

procedure TestTPSDTPack.TearDown;
begin

end;

var
  runner : ITestRunner;
  results : IRunResults;
  logger : ITestLogger;
  nunitLogger : ITestLogger;

const
  QuietMode: Boolean = False;  // False = Detailed test log


begin

  try
    //Create the runner
    runner := TDUnitX.CreateRunner;
    runner.UseRTTI := True;
    //tell the runner how we will log things
    logger := TDUnitXConsoleLogger.Create(QuietMode);
    nunitLogger := TDUnitXXMLNUnitFileLogger.Create;
    runner.AddLogger(logger);
    runner.AddLogger(nunitLogger);

    TDUnitX.RegisterTestFixture(TestTPSDTPack);

    //Run tests
    results := runner.Execute;

    {$IFNDEF CI}
      //We don't want this happening when running under CI.
      System.Write('Done.. press <Enter> key to quit.');
      System.Readln;
    {$ENDIF}
  except
    on E: Exception do
      System.Writeln(E.ClassName, ': ', E.Message);
  end;
end.
@vincentparrett
Copy link
Member

I haven't had chance to fully look into this, but in DUnitX.Test.pas, in TDUnitXTestCase.GetName, just comment out everything before

result := FName

That seems to fix it, however we lose the test case parameters altogether.. so perhaps we need a better way to describe test cases.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants