Recent

Author Topic: Using FPCUnit. How to put window with project code and with tests together  (Read 5362 times)

xaskell

  • New member
  • *
  • Posts: 7
I mean it is quite uncomfortable when you see only tests. I would like possibility to change code in my program and test it in the same time.
How to do it easily? I'm newbie, so no offence  :-[.

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 219
Do you search something like http://delphisorcery.blogspot.com/2015/02/testinsight-unit-testing-like-pro.html but for Lazarus?

Yeah, that would be great.

xaskell

  • New member
  • *
  • Posts: 7
Do you search something like http://delphisorcery.blogspot.com/2015/02/testinsight-unit-testing-like-pro.html but for Lazarus?

Yeah, that would be great.

I searched a little. But I didn't find something.
I just found old subject here on forum
http://forum.lazarus.freepascal.org/index.php?topic=15681.0

With the same problem. It looks like here no integration of tests in the project.  :'(
But anyway maybe exists some additional packet or something else.
It's sad that you can't open several projects in Lazarus at the same time
and can't integrate tests directly to your project. I hope next stable release will receive this feature

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 219
It's sad that you can't open several projects in Lazarus at the same time

There is a project group package in development: http://wiki.freepascal.org/Project_Groups

and can't integrate tests directly to your project. I hope next stable release will receive this feature

Feel free to develop an IDE extension package for FPTest http://wiki.freepascal.org/FPTest.

taazz

  • Hero Member
  • *****
  • Posts: 5365
It's sad that you can't open several projects in Lazarus at the same time

There is a project group package in development: http://wiki.freepascal.org/Project_Groups

and can't integrate tests directly to your project. I hope next stable release will receive this feature

Feel free to develop an IDE extension package for FPTest http://wiki.freepascal.org/FPTest.
I don't think he asks for integrated testing extension, he simple does not understand the concepts behind unit testing to test his code.

Well here goes nothing.
1) a unit testing framework does not test applications only procedures, functions and methods of classes.
2) integration with the IDE it self is almost impossible in the extend you envision or seek to use.

The idea behind a unit testing framework is to write code that, in essence, defines the boundaries of responsibility of a piece of code and tests for correct results on those boundaries.
This gives you a stable base to keep on building and extending your code, with out worrying if a change breaks something fundamental in your code base and produces bugs in portion of the code that you did not touch during the expansion, by allowing you to run all the tests you have written so far, over and over again, to make sure that everything works.

It is not mend to be used as an interpreter for you code and in essence create an IDE that when you change the color of your font it imidiatetly show the new color on screen inside your application. That is something different altogether.

The best way to test your application is to compile it and use it. Actually this is the only way to do so. If you could scale back your requirements and simple inform us what you try to do, be specific for the task at hand, we might be able to come up with a working process that will help you.

In short read up on unit testing, if you have any questions ask, as always try to  minimize the question to the problem at hand and do not generalize, otherwise you will get a number of answers that probably have nothing to do with your problem.
« Last Edit: August 26, 2017, 11:03:08 pm by taazz »
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

xaskell

  • New member
  • *
  • Posts: 7
Thank you guys. I appreciate your help. Here are really good community.
I know about TDD more or less. I guess Ondrej Pokorny understood me right.

Thanks again for Project Groups it can be useful for me.

Here I'll show what I'd like to have at Lazarus.
Attached file is Netbeans. There are I can see test in results in one window with code editor


Leledumbo

  • Hero Member
  • *****
  • Posts: 8325
  • Programming + Glam Metal + Tae Kwon Do = Me
All existing unit testing frameworks integrate with the IDE as packages for easy generation of test projects, which don't differ at all with any other projects. In order to make something like that NetBeans extension, the same route must be taken: build an IDE extension that integrates with the IDE to run and parse unit test results. Otherwise, since test projects are regular projects, you can just run it with IDE's Run (without debugging, if you want) feature and watch the output in messages window (don't select GUI test project, of course).

xaskell

  • New member
  • *
  • Posts: 7
Thank you. It's sad that I'm a newbie at Lazarus so I can't write my own extension. At least now.
For me and it looks like not only for me it is more comfortable to see test results with code editor.
 I saw several old topics here about the same inconvenience.


Graeme

  • Hero Member
  • *****
  • Posts: 1431
    • Graeme on the web
Thank you. It's sad that I'm a newbie at Lazarus so I can't write my own extension. At least now.
For me and it looks like not only for me it is more comfortable to see test results with code editor.
 I saw several old topics here about the same inconvenience.

I prefer to have unit tests run outside the confines of the IDE. So I make use of Project Groups (thank goodness Lazarus finally has that functionality too). One project is you actual project. Another project is your Unit Testing project. If you run a older Lazarus that doesn't have project groups support, then simply make a batch file to build your Unit Test Project. I then run the Lazarus IDE with the actual project and open the needed unit test units too. I then run a console window in which I launch the batch file to rebuild the unit test project. I prefer running GUI Test Runners while developing my software, and I can see which tests failed and the line numbers in the units that failed. With the IDE already open, I can instantly modify and fix the code as needed and then rebuild and run the units tests again. MSEide even has the ability to launch pre and post Compile action. So you can hook the batch file for building unit tests into the project settings. So when you compile the project, the unit tests are automatically compiled afterwards. I don't think Lazarus IDE has a similar feature to that.

I can also add that if you are doing Test Driven Development, you can just as well open the Unit Test project and only work in that using Lazarus IDE. This allows you to edit units and test units, and F9 to run the unit tests. Once everything is implement, then switch over to the "gui project" and hook all functionality together.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Ondrej Pokorny

  • Full Member
  • ***
  • Posts: 219
MSEide even has the ability to launch pre and post Compile action. So you can hook the batch file for building unit tests into the project settings. So when you compile the project, the unit tests are automatically compiled afterwards. I don't think Lazarus IDE has a similar feature to that.

It has. I use it a lot: Project Options -> Compiler Commands

Wosi

  • New Member
  • *
  • Posts: 21
FWIW, I do test driven development in VSCode + OmniPascal. Since VSCode comes with a built in task system and terminal widget I can compile and run tests with a shortcut and see the test results below the code inside the editor window.

xaskell

  • New member
  • *
  • Posts: 7
FWIW, I do test driven development in VSCode + OmniPascal. Since VSCode comes with a built in task system and terminal widget I can compile and run tests with a shortcut and see the test results below the code inside the editor window.
This way is comfortable for me too. When you get used to it, it is hard to use another way.
Guys, thank you for so many answers, for so many ideas. I'll use something. Project groups for beginning maybe.
Later I'll write my extension I hope  ;)

Graeme

  • Hero Member
  • *****
  • Posts: 1431
    • Graeme on the web
It has. I use it a lot: Project Options -> Compiler Commands

Good to know. Thanks for correcting that information.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Mark Paley

  • Newbie
  • Posts: 1
The advantage of having the tests as a window within the main program is that the tests can be run from the Main Menu at any point during the program's execution.  Running the tests at various times throughout the program's execution makes it easier to spot errors which crop up over time, not merely at the program's initial execution.

It's nice to be able to say, at any point in time, "I think I'll run a Test right now, just to see if anything comes up Red."

Here's how I did it: I created a ActionList TAction item and named it "actTest".  I created a MainMenu item named "Test", and assigned it the TAction actTest.  I created the TestCase1 unit from the Lazarus Menu, "New..." | Module | FPCUnit Test Case.  I added "TestCase1, GuiTestRunner" to the uses clause of my main program.  With the Project Inspector, I added "fpcunitrunner" as a Required Package to my project.

I assigned the keyboard shortcut Ctrl+T to the Test Menuitem.  So I can quickly run a test by pressing Ctrl+T then F9.

Although probably unnecessary, I also created an inherited class from TGuiTestRunner, just so I could create my own FormClose method, to ensure that I don't create more than 1 instance of the MyGuiTestRunner object.

If you don't want end users to be able to see the tests, you could just hide the "Test" menuitem before compiling your distribution version.  However, it might give customers confidence in your program if they are able to run tests, too.  Further, a customer running a test might be able to give you insight about program bugs later.

unit MyUnit1

uses ... TestCase1, GuiTestRunner ...

type
  { TMyGuiTestRunner }
  TMyGuiTestRunner = class(TGuiTestRunner)
  procedure FormClose(Sender: Tobject; var Closeaction: Tcloseaction);
  end;
 
  { TfrMain, my program's main form }
  TfrMain = class(TForm)
  ...
    actTest: TAction;   
    procedure actTestExecute(Sender: TObject);
  ...
 
var
    MyGuiTestRunner: TMyGUITestRunner;
   
procedure TMyGuiTestRunner.FormClose(Sender: Tobject; var Closeaction: Tcloseaction);
begin
  CloseAction := caFree;
  MyGuiTestRunner := nil;
end;

procedure TfrMain.actTestExecute(Sender: TObject);
begin
  if (MyGuiTestRunner = nil) then
    Application.CreateForm(TGUITestRunner, MyGuiTestRunner);
  MyGuiTestRunner.Show;
end;

« Last Edit: March 31, 2021, 08:40:48 am by Mark Paley »

 

TinyPortal © 2005-2018