Recent

Author Topic: Unit Testing Mock library  (Read 4608 times)

seaton

  • New Member
  • *
  • Posts: 48
Unit Testing Mock library
« on: September 22, 2015, 03:30:38 pm »
Can anyone recommend a Mock library for Lazarus, I found Pascal Mock via google but doesn't seem to any active development so am not sure what else is out there.

Regards,

Stephen...

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: Unit Testing Mock library
« Reply #1 on: September 22, 2015, 04:28:42 pm »
Look at this:
http://wiki.freepascal.org/FPTest

you can also search for "FPTest" and "FPCTest" in the forum for more information

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Unit Testing Mock library
« Reply #2 on: September 22, 2015, 06:48:39 pm »
Look at this:
http://wiki.freepascal.org/FPTest
I'm not sure FPTest has mock feature, as is FPCUnit.

seaton

  • New Member
  • *
  • Posts: 48
Re: Unit Testing Mock library
« Reply #3 on: September 23, 2015, 12:15:44 am »
Thanks for the reply guys,

Yes I'm actually using this unit and AFAIK it doesn't support Mock, is just unit testing

Stephen

jwdietrich

  • Hero Member
  • *****
  • Posts: 1232
    • formatio reticularis
Re: Unit Testing Mock library
« Reply #4 on: September 23, 2015, 01:45:07 am »
Did you really try Pascal Mock, and it doesn't work?
function GetRandomNumber: integer; // xkcd.com
begin
  GetRandomNumber := 4; // chosen by fair dice roll. Guaranteed to be random.
end;

http://www.formatio-reticularis.de

Lazarus 2.2.6 | FPC 3.2.2 | PPC, Intel, ARM | macOS, Windows, Linux

seaton

  • New Member
  • *
  • Posts: 48
Re: Unit Testing Mock library
« Reply #5 on: September 23, 2015, 06:43:27 pm »
@ jwdietrich No not yet, I haven't given it a go yet as I saw that there hadn't been any active development lately and I also wanted to see what others were using before I went down the path of trying it.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: Unit Testing Mock library
« Reply #6 on: September 23, 2015, 09:06:56 pm »
It still works, but requires little changes in the code. Somehow my FPC 3.1.1 is confused when it sees:
Code: [Select]
    //: Set return value
    procedure Returns(AValue: Variant); overload;
    procedure Returns(AValue: Pointer); overload;
    procedure Returns(AValue: IUnknown); overload;
    procedure Returns(AValue: TObject); overload;
And it decides that calls to this method with integer argument doesn't match any of them, while it should match the Variant one. Probably a compiler bug. It's trivial to typecast to Variant, however. There are only a few.

I use the newest Delphi project converter from my Lazarus trunk and greatly it knows that FPTest is DUnit compatible so it adds fptest automatically to the project dependency and it compiles just fine.

The test is not clean, though. 1 error 1 failure 5 warnings. No memory leak.

Attached is the modified archive.

seaton

  • New Member
  • *
  • Posts: 48
Re: Unit Testing Mock library
« Reply #7 on: September 24, 2015, 04:09:57 pm »
@ Leledumbo  Thanks for that, Will check it out.

 

TinyPortal © 2005-2018