A Open Source Mocking framework for Delphi XE2 or later
Pascal PHP
Latest commit 882e597 Nov 29, 2016 @vincentparrett vincentparrett committed on GitHub Merge pull request #103 from henriquewerlang/master
Problemas com parâmetros de função como enumeradores
Permalink
Failed to load latest commit information.
Build Fixed build script. Aug 15, 2013
DUnitXML @ e446bfb Updated DUnitXML submodule reference. Jul 11, 2014
Examples Fixed XE2 compiler bugs, and also removed DUnitX.Utils usage as it sh… Aug 21, 2016
Tests Encontrei o mesmo problema, de não carregar o retorno do valor em out… Oct 14, 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 Adicionado um procedimento novo, para disparar um raise quando os par… Oct 14, 2016
Delphi.Mocks.Expectation.pas Fixed expectations to use matches as well. Jul 30, 2015
Delphi.Mocks.Helpers.pas Fixed XE2 compiler bugs, and also removed DUnitX.Utils usage as it sh… Aug 21, 2016
Delphi.Mocks.Interfaces.pas Added param matchers to Expectations Sep 9, 2014
Delphi.Mocks.MethodData.pas Adicionado um procedimento novo, para disparar um raise quando os par… Oct 14, 2016
Delphi.Mocks.ObjectProxy.pas Fixed XE2 compiler bugs, and also removed DUnitX.Utils usage as it sh… Aug 21, 2016
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 Adicionado um procedimento novo, para disparar um raise quando os par… Oct 14, 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
Delphi.Mocks.inc Unnecessary DELPHI_XE7 define removed in few cases May 22, 2016
Delphi.Mocks.pas Adicionado um procedimento novo, para disparar um raise quando os par… Oct 14, 2016
DelphiMocks.groupproj more fixes Sep 9, 2011
LICENSE.txt updated readme and added license Sep 9, 2011
README.md 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 Fixed XE2 compiler bugs, and also removed DUnitX.Utils usage as it sh… Aug 21, 2016
Sample1.dproj Fixed XE2 compiler bugs, and also removed DUnitX.Utils usage as it sh… Aug 21, 2016
Sample1Main.pas Fixed compiler issue with an example that was using the old It record. Jul 30, 2015

README.md

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.

Example

unit Delphi.Mocks.Examples.Interfaces;

interface

uses
  SysUtils,
  DUnitX.TestFramework,
  Delphi.Mocks;

type
  {$M+}
  TSimpleInterface = Interface
    ['{4131D033-2D80-42B8-AAA1-3C2DF0AC3BBD}']
    procedure SimpleMethod;
  end;

  TSystemUnderTestInf = Interface
    ['{5E21CA8E-A4BB-4512-BCD4-22D7F10C5A0B}']
    procedure CallsSimpleInterfaceMethod;
  end;
  {$M-}

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

  TMockObjectTests = class
  published
    procedure Simple_Interface_Mock;
  end;

implementation

uses
  Rtti;

{ TMockObjectTests }

procedure TMockObjectTests.Simple_Interface_Mock;
var
  mock : TMock<TSimpleInterface>;
  sutObject : TSystemUnderTestInf;
begin
  //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.
  mock.Setup.Expect.AtLeastOnce.When.SimpleMethod;

  //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.
  sutObject.CallsSimpleInterfaceMethod;

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

{ TSystemUnderTest }

procedure TSystemUnderTest.CallsSimpleInterfaceMethod;
begin
  FInternalInf.SimpleMethod;
end;

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

end.