How to run FPCUnit? lazarus / 21-General ---------------------------------------------------------------------- ReinaldoSergioPTBR · 2021-11-15 18:29 How to run FPCUnit? ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-11-15 20:26 Boas Reinaldo, Quote from: ReinaldoSergioPTBR on November 15, 2021, 07:29:11 pmHow to run FPCUnit? Are you talking about the CLI(Command Line Interface) version or about the GUI(Graphical Usage Interface) version? If you're talking about the CLI version: name_of_binary --all --format=plain If it's the GUI version: There are buttons on the top of the form to run all your tests. If you're asking how does one go about implementing Unit Testing, then that's a very big topic and we can only point you to places to learn. The topic is way too big to just try and make you grasp it via a couple of messages on the forum. What I can quickly tell you is that, no matter what route you take(CLI or GUI), you start by creating a new project and then choose the CLI or GUI options. After that, everything depends on the data structures you've created for your application. Please give us a hint of what you're after. Grande abraço, Gus ---------------------------------------------------------------------- ReinaldoSergioPTBR · 2021-11-15 20:54 I already managed to create a test class Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit TstUnit; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, fpcunit, testutils, testregistry, uPessoa; type   { TTestCase1 }   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. The issue now is that I don't know how to run the test, whether it's CLI or GUI, it would be better GUI, but the issue is that I don't know where to click or which command to run. When I order it to compile it, it's opening the program, don't test it. It opens this form Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit uTesteUnitario; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, DBCtrls; type   { TfTesteUnitario }   TfTesteUnitario = class(TForm)    Button1: TButton;    DBNavigator1: TDBNavigator;  private   public   end; var  fTesteUnitario: TfTesteUnitario; implementation {$R *.lfm} end. [Edited to add code tags - please read How to use the Forums.] ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-11-15 21:30 Boas Reinaldo, First of all, please wrap you code with [ code ] BBTags so your code is easy to look at. There's a drop down with the name Code on the top of the editor and you can choose multiple types of code. Secondly, looks like you're missing the Program that will then use your Units. Since you already have done some of the work with the units, you're just missing the Program. I'll give you the necessary Program examples for CLI and GUI, but next time, please use: CLI: Project->New Project...->FPCUnit Console test ApplicationGUI: Project->new project...->FPCUnit Test Application The Program for the CLI version: MyTestRunnerCLI.lpr Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program MyTestRunnerCLI; {$mode objfpc}{$H+} uses  Classes, consoletestrunner, TstUnit; type   { TMyTestRunner }   TMyTestRunner = class(TTestRunner)  protected  // override the protected methods of TTestRunner to customize its behavior  end; var  Application: TMyTestRunner; begin  Application := TMyTestRunner.Create(nil);  Application.Initialize;  Application.Title:='MyTestRunnerCLI';  Application.Run;  Application.Free;end. The Program for the GUI version: MyTestRunnerGUI.lpr Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program MyTestRunnerGUI; {$mode objfpc}{$H+} uses  Interfaces, Forms, GuiTestRunner, TstUnit; {$R *.res} begin  Application.Initialize;  Application.CreateForm(TGuiTestRunner, TestRunner);  Application.Run;end. Then, on Lazarus open the LPR file and it will create a LPI file to accompany the whole set of files needed. If you want to have a look at how I setup my tests, have a look at this repo: https://github.com/gcarreno/lazJSONRPCData/tree/main/tests There you'll see that I share the same Units between the CLI version and the GUI version. I tend to use the GUI version to develop the tests, since it's quicker to cycle with the GUI app. I use the CLI version in conjunction with my setup-lazarus GitHub action to do some CI(Continuous Integration) on the GitHub virtual machine runners. Hope this helps. Grande abraço, Gus ---------------------------------------------------------------------- thierrybo · 2021-11-15 21:35 What about FPTest, the wiki says it is a much improved fpcunit version? ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-11-15 21:59 Hey thierrybo, Quote from: thierrybo on November 15, 2021, 10:35:50 pmWhat about FPTest, the wiki says it is a much improved fpcunit version? I wasn't aware of that option!! Thank you soooo much for the suggestion. I'll have a look at that! Cheers, Gus ---------------------------------------------------------------------- ReinaldoSergioPTBR · 2021-11-16 14:39 Quote from: Gustavo 'Gus' Carreno on November 15, 2021, 10:30:47 pmBoas Reinaldo, First of all, please wrap you code with [ code ] BBTags so your code is easy to look at. There's a drop down with the name Code on the top of the editor and you can choose multiple types of code. Secondly, looks like you're missing the Program that will then use your Units. Since you already have done some of the work with the units, you're just missing the Program. I'll give you the necessary Program examples for CLI and GUI, but next time, please use: CLI: Project->New Project...->FPCUnit Console test ApplicationGUI: Project->new project...->FPCUnit Test Application The Program for the CLI version: MyTestRunnerCLI.lpr Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program MyTestRunnerCLI; {$mode objfpc}{$H+} uses  Classes, consoletestrunner, TstUnit; type   { TMyTestRunner }   TMyTestRunner = class(TTestRunner)  protected  // override the protected methods of TTestRunner to customize its behavior  end; var  Application: TMyTestRunner; begin  Application := TMyTestRunner.Create(nil);  Application.Initialize;  Application.Title:='MyTestRunnerCLI';  Application.Run;  Application.Free;end. The Program for the GUI version: MyTestRunnerGUI.lpr Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i program MyTestRunnerGUI; {$mode objfpc}{$H+} uses  Interfaces, Forms, GuiTestRunner, TstUnit; {$R *.res} begin  Application.Initialize;  Application.CreateForm(TGuiTestRunner, TestRunner);  Application.Run;end. Then, on Lazarus open the LPR file and it will create a LPI file to accompany the whole set of files needed. If you want to have a look at how I setup my tests, have a look at this repo: https://github.com/gcarreno/lazJSONRPCData/tree/main/tests There you'll see that I share the same Units between the CLI version and the GUI version. I tend to use the GUI version to develop the tests, since it's quicker to cycle with the GUI app. I use the CLI version in conjunction with my setup-lazarus GitHub action to do some CI(Continuous Integration) on the GitHub virtual machine runners. Hope this helps. Grande abraço, Gus First of all, I'm sorry I didn't wrap my code with BBTags. Secondly, thank you very much, being able to run the FPCUnit GUI and run the tests ---------------------------------------------------------------------- Gustavo 'Gus' Carreno · 2021-11-16 21:18 Boas Reinaldo, Quote from: ReinaldoSergioPTBR on November 16, 2021, 03:39:10 pmFirst of all, I'm sorry I didn't wrap my code with BBTags. No probs, you've corrected your mistake and that's all that counts!! Quote from: ReinaldoSergioPTBR on November 16, 2021, 03:39:10 pmSecondly, thank you very much, being able to run the FPCUnit GUI and run the tests That's AWESOME!! You're more than welcome! Grande abraço, Gus