Lazarus

Free Pascal => General => Topic started by: ReinaldoSergioPTBR on November 12, 2021, 08:25:07 pm

Title: How to use FPCunit?
Post by: ReinaldoSergioPTBR 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 (https://wiki.lazarus.freepascal.org/Forum).]
Title: Re: How to use FPCunit?
Post by: thierrybo on November 12, 2021, 11:29:31 pm
Useful readings:

https://wiki.freepascal.org/fpcunit
https://www.freepascal.org/~michael/articles/fpcunit/fpcunit.pdf
http://sergworks.wordpress.com/2012/08/31/introduction-to-unit-testing-with-lazarus/
http://www.pp4s.co.uk/main/tu-testing-auto2.html
Title: Re: How to use FPCunit?
Post by: Leledumbo 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