Forum > General

How to use FPCunit?

(1/1)

ReinaldoSergioPTBR:
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  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  TTestCase1 = class(TTestCase)  private    FPessoa : TPessoa;  protected    procedure SetUp; override;    procedure TearDown; override;  published    procedure TestHookUp;    procedure TesteTratarCPFCNPJ;  end; implementation procedure TTestCase1.TestHookUp;begin  Fail('Escreva seu prĂ³prio teste');end; procedure TTestCase1.TesteTratarCPFCNPJ;var  Resultado : String;begin  Resultado := FPessoa.TratarCPFCNPJ('123.123.123-12');  Assert(Resultado = '12312312312', 'TPessoa.TratarCPFCNPJ retornou um Erro');end; procedure TTestCase1.SetUp;begin  FPessoa := TPessoa.Create;end; procedure TTestCase1.TearDown;begin  FreeAndNil(FPessoa);end; initialization   RegisterTest(TTestCase1);end.
[Edited to add code tags - please read How to use the Forums.]

thierrybo:
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

Leledumbo:

--- Quote from: 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.

--- End quote ---
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.

Navigation

[0] Message Index

Go to full version