Skip to content
A Open Source Mocking framework for Delphi XE2 or later
Pascal C++ PHP
Failed to load latest commit information.
Build Fixed build script. Aug 15, 2013
DUnitXML @ e446bfb Updated DUnitXML submodule reference. Jul 11, 2014
Examples Fixed compiler error I added. Jun 1, 2016
Tests Merge pull request #97 from AndreasDDi/patch-2 Jun 1, 2016
.gitignore Fixed comparison when using Variant args. Was raising AV when trying … Oct 4, 2013
.gitmodules Updated to include DUnit XML module. Aug 15, 2013
Delphi.Mocks.AutoMock.pas Automock to return proxy as type requested. Aug 5, 2015
Delphi.Mocks.Behavior.pas Handled ParamMatcher issue with undefined order of executions for Params Jul 30, 2015
Delphi.Mocks.Expectation.pas Fixed expectations to use matches as well. Jul 30, 2015
Delphi.Mocks.Helpers.pas Allow TValue to be able to compare TGUIDs Aug 11, 2015
Delphi.Mocks.Interfaces.pas Added param matchers to Expectations Sep 10, 2014
Delphi.Mocks.MethodData.pas Fix some bugs and failed tests related to DUnitX migration. Nov 15, 2015
Delphi.Mocks.ObjectProxy.pas TObjectProxy changes: added possibility of creating instance of objec… Nov 16, 2015
Delphi.Mocks.ParamMatcher.pas Memory leak bug correction. Oct 13, 2015
Delphi.Mocks.Proxy.TypeInfo.pas Add files via upload May 31, 2016
Delphi.Mocks.Proxy.pas Merge pull request #97 from AndreasDDi/patch-2 Jun 1, 2016
Delphi.Mocks.ReturnTypePatch.pas Implementation of AutoMocking. Jul 31, 2015
Delphi.Mocks.Utils.pas Automocks except when mocking interface or object is not possible. Aug 5, 2015
Delphi.Mocks.Validation.pas Automocks except when mocking interface or object is not possible. Aug 5, 2015
Delphi.Mocks.VirtualInterface.pas Fix for XE2 Update 2 Nov 4, 2011
Delphi.Mocks.VirtualMethodInterceptor.pas Fix for XE2 Update 2 Nov 4, 2011
Delphi.Mocks.WeakReference.pas Fiz a implementação com a sugestão do @fabriciocolombo, apenas nas cl… Nov 26, 2015
Delphi.Mocks.When.pas Major rework of implements functionality. Some tests not working, don… Jul 11, 2014 Unnecessary DELPHI_XE7 define removed in few cases May 22, 2016
Delphi.Mocks.pas Merge pull request #97 from AndreasDDi/patch-2 Jun 1, 2016
DelphiMocks.groupproj more fixes Sep 9, 2011
LICENSE.txt updated readme and added license Sep 9, 2011 Updated the readme to have a better description Sep 21, 2015
Sample1.RES Started working on Stubs.. still need to improve .Utils.GetDefaultValue Sep 8, 2013
Sample1.dpr Corrected location of the example projects in the sample project. Sep 21, 2015
Sample1.dproj Corrected location of the example projects in the sample project. Sep 21, 2015
Sample1Main.pas Fixed compiler issue with an example that was using the old It record. Jul 30, 2015

Delphi Mocks

Delphi Mocks is a simple mocking framework for Delphi XE2 or later. It makes use of RTTI features that are only available in Delphi XE2, however I do hope to be able to get it working with earlier versions of Delphi (2010 or later) at some stage.


unit Delphi.Mocks.Examples.Interfaces;



  TSimpleInterface = Interface
    procedure SimpleMethod;

  TSystemUnderTestInf = Interface
    procedure CallsSimpleInterfaceMethod;

  TSystemUnderTest = class(TInterfacedObject, TSystemUnderTestInf)
    FInternalInf : TSimpleInterface;
    constructor Create(const ARequiredInf: TSimpleInterface);
    procedure CallsSimpleInterfaceMethod;

  TMockObjectTests = class
    procedure Simple_Interface_Mock;



{ TMockObjectTests }

procedure TMockObjectTests.Simple_Interface_Mock;
  mock : TMock<TSimpleInterface>;
  sutObject : TSystemUnderTestInf;
  //SETUP: Create a mock of the interface that is required by our system under test object.
  mock := TMock<TSimpleInterface>.Create;

  //SETUP: Add a check that SimpleMethod is called atleast once.

  //SETUP: Create the system under test object passing an instance of the mock interface it requires.
  sutObject := TSystemUnderTest.Create(mock.Instance);

  //TEST: Call CallsSimpleInterfaceMethod on the system under test.

  //VERIFY: That our passed in interface was called at least once when CallsSimpleInterfaceMethod was called.
  mock.Verify('CallsSimpleInterfaceMethod should call SimpleMethod');

{ TSystemUnderTest }

procedure TSystemUnderTest.CallsSimpleInterfaceMethod;

constructor TSystemUnderTest.Create(const ARequiredInf: TSimpleInterface);
  FInternalInf := ARequiredInf;

Something went wrong with that request. Please try again.