Recent

Author Topic: How to use FPCunit?  (Read 2402 times)

ReinaldoSergioPTBR

  • New Member
  • *
  • Posts: 19
How to use FPCunit?
« on: November 12, 2021, 08:25:07 pm »
How to use FPCunit?
I already created the function for the test but I don't know how to display the test result.

Code: Pascal  [Select][+][-]
  1.   TTestCase1 = class(TTestCase)
  2.   private
  3.     FPessoa : TPessoa;
  4.   protected
  5.     procedure SetUp; override;
  6.     procedure TearDown; override;
  7.   published
  8.     procedure TestHookUp;
  9.     procedure TesteTratarCPFCNPJ;
  10.   end;
  11.  
  12. implementation
  13.  
  14. procedure TTestCase1.TestHookUp;
  15. begin
  16.   Fail('Escreva seu próprio teste');
  17. end;
  18.  
  19. procedure TTestCase1.TesteTratarCPFCNPJ;
  20. var
  21.   Resultado : String;
  22. begin
  23.   Resultado := FPessoa.TratarCPFCNPJ('123.123.123-12');
  24.   Assert(Resultado = '12312312312', 'TPessoa.TratarCPFCNPJ retornou um Erro');
  25. end;
  26.  
  27. procedure TTestCase1.SetUp;
  28. begin
  29.   FPessoa := TPessoa.Create;
  30. end;
  31.  
  32. procedure TTestCase1.TearDown;
  33. begin
  34.   FreeAndNil(FPessoa);
  35. end;
  36.  
  37. initialization
  38.  
  39.   RegisterTest(TTestCase1);
  40. end.

[Edited to add code tags - please read How to use the Forums.]
« Last Edit: November 13, 2021, 12:56:18 am by trev »


Leledumbo

  • Hero Member
  • *****
  • Posts: 8402
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to use FPCunit?
« Reply #2 on: December 07, 2021, 03:49:44 am »
How to use FPCunit?
I already created the function for the test but I don't know how to display the test result.
A unit test program is a separate program from your actual program. If you use the project wizard, it will have a .lpr containing the unit test program. Just run it to see the unit test result. Use the GUI project if you want a dashboard style output rather than console.

 

TinyPortal © 2005-2018