Recent

Author Topic: How to run fpcunit test case (TTestCase) in Lazarus?  (Read 13824 times)

mvampire

  • Jr. Member
  • **
  • Posts: 62
How to run fpcunit test case (TTestCase) in Lazarus?
« on: January 03, 2012, 07:52:57 pm »
Dear forum members.

Can I ask for your help with unit testing?

I have written a simple unit test (using TTestCase) class.
I have Ubuntu 10.04 amd64, fpc 2.4.0, Lazarus 0.9.28.2

And I don't understand how can I run the test case I wrote... How to do it?

Thank You in advance.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #1 on: January 04, 2012, 03:02:01 am »
Create a unit test project, the interface and program code would be automatically built. Simply register your test cases in initialization section of your units. To execute, simply run like any other project.

mvampire

  • Jr. Member
  • **
  • Posts: 62
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #2 on: January 04, 2012, 07:05:00 am »
Is there a way to create Unit tests in the same project with tested units (without making separate project for tests), like in Java/Eclipse?

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #3 on: January 04, 2012, 09:55:28 am »
No, unit test executor is another project, it's no different at all from other projects.

mvampire

  • Jr. Member
  • **
  • Posts: 62
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #4 on: January 04, 2012, 11:06:15 am »
Then it's quite uncomfortable, because, as I have undestood, only 1 project can be opened in Lazarus at once, right?

So test driven development (http://en.wikipedia.org/wiki/Test-driven_development) or just any tests are hard to implement, because I need every time to close test project, open main project, close main, open test, close test, open main, ...

Or I don't understand it?

What will be the right project / folders structure then?
What is the right way to access main project units from the test project?
How to use it in continious integration systems?

Is there any documentation/tutorial on unit testing (creating, organising, running tests, mocking, etc.) in Lazarus?
« Last Edit: January 04, 2012, 12:05:23 pm by mvampire »

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #5 on: January 04, 2012, 02:14:24 pm »
Then it's quite uncomfortable, because, as I have undestood, only 1 project can be opened in Lazarus at once, right?

So test driven development (http://en.wikipedia.org/wiki/Test-driven_development) or just any tests are hard to implement, because I need every time to close test project, open main project, close main, open test, close test, open main, ...
The way I would do it: 2 Lazarus IDEs open - one with main project, other with test project. Test project references units in main project; whenever main code unit changes, Lazarus IDE for test project should recognize changed files and you can reload.

As for CI servers: you can use e.g. the lazbuild console program to compile Lazarus projects from command line... I'd be interested in a writeup on using CI servers with Lazarus...

I'm sure more knowledgeable people will have better suggestions; if you don't get more here, you can ask on the Lazarus mailing list.

Also, recentley Graeme Geldenhuys wrote a wiki page on his development of a unit test framework for FPC/Lazarus...

Good luck.
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

mvampire

  • Jr. Member
  • **
  • Posts: 62
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #6 on: January 04, 2012, 02:23:45 pm »
Also, recentley Graeme Geldenhuys wrote a wiki page on his development of a unit test framework for FPC/Lazarus...

Can you write a link, please...

BigChimp

  • Hero Member
  • *****
  • Posts: 5740
  • Add to the wiki - it's free ;)
    • FPCUp, PaperTiger scanning and other open source projects
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #7 on: January 04, 2012, 02:25:28 pm »
Also, recentley Graeme Geldenhuys wrote a wiki page on his development of a unit test framework for FPC/Lazarus...

Can you write a link, please...
http://wiki.lazarus.freepascal.org/FPTest

Note: there also is the FPCUnit framework (which has a Lazarus GUI frontend as well: e.g. the FPCUnitTestRunner package) which has similar functionality. FPCUnit is used AFAIK by the FPC developers; FPTest apparently is more advanced...
« Last Edit: January 04, 2012, 02:27:08 pm by BigChimp »
Want quicker answers to your questions? Read http://wiki.lazarus.freepascal.org/Lazarus_Faq#What_is_the_correct_way_to_ask_questions_in_the_forum.3F

Open source including papertiger OCR/PDF scanning:
https://bitbucket.org/reiniero

Lazarus trunk+FPC trunk x86, Windows x64 unless otherwise specified

mvampire

  • Jr. Member
  • **
  • Posts: 62
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #8 on: January 04, 2012, 02:56:23 pm »
Thank you.
However, I will be dreaming about:

1) Eclipse-style unit tests in Lazarus, when tests are in the same project, and I can right click on the unit/test (or package with multiple tests) and run it as a test.
2) more sophisticated, again, Eclipse-style Project Inspector / Package Explorer and clear project structure
3) possibility to open several projects in 1 IDE instance
4) possibility to have several runnable units (classes) in 1 project - also like in Eclipse.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #9 on: January 05, 2012, 03:10:01 am »
Quote
So test driven development (http://en.wikipedia.org/wiki/Test-driven_development) or just any tests are hard to implement, because I need every time to close test project, open main project, close main, open test, close test, open main, ...

Or I don't understand it?
If you follow test driven development, then most of the time you would only deal with the test project. Only when all the tests have passed you would glue the units in the main project (and you start integration testing).

mvampire

  • Jr. Member
  • **
  • Posts: 62
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #10 on: January 05, 2012, 07:32:29 pm »
In principle, yes.
But, after JavaEE programming in Eclipse I would say, that unit tests in Lazarus, how they are organised, seem totally unusable.
And, IMHO, this is one on the most important factors, or even the most important which limits dissemination and distribution of Lazarus and FreePascal.
It's not possible to create any application without testing it. And when tests are so uncomfortable...

I understand, that FP is not Java, and Lazarus - not Eclipse. But it would be really great to have more comfortable unit tests (I even don't say anything about mocking). It would simplify life of many people then :)
« Last Edit: January 05, 2012, 07:35:29 pm by mvampire »

Graeme

  • Hero Member
  • *****
  • Posts: 1428
    • Graeme on the web
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #11 on: October 26, 2012, 01:20:45 am »
1) Eclipse-style unit tests in Lazarus, when tests are in the same project, and I can right click on the unit/test (or package with multiple tests) and run it as a test.
All that is needed is for Lazarus to support  Project Groups - like the Delphi IDE does. I have no idea how hard this would be to implement or if somebody is already working on this.

But as another posted said. When doing TDD you are unit testing business logic (99% of the time) - thus no GUI code - so you will be mostly in the unit test project developing those business classes and test suites. This is how I work.
--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

Calliopebrook

  • Newbie
  • Posts: 1
    • http://www.abercrombiezurich.eu/
Re: How to run fpcunit test case (TTestCase) in Lazarus?
« Reply #12 on: October 29, 2012, 07:23:42 am »
In principle, yes.
But, after JavaEE programming in Eclipse I would say, that unit tests in Lazarus, how they are organised, seem totally unusable.
And, IMHO, this is one on the most important factors, or even the most important which limits dissemination and distribution of Lazarus and FreePascal.
It's not possible to create any application without testing it. And when tests are so uncomfortable...

I understand, that FP is not Java, and Lazarus - not Eclipse. But it would be really great to have more comfortable unit tests (I even don't say anything about mocking). It would simplify life of many people then :)
:-*

 

TinyPortal © 2005-2018