Questions tagged [delphi-mocks]

Delphi Mocks is an open source mocking framework for Delphi XE2 or later versions.

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, though work is being done to get it working with earlier versions of Delphi (2010 or later).

Resources:

19 questions
10
votes
3 answers

Delphi-Mocks: Mocking a class with parameters in the constructor

I'm starting to use the Delphi-Mocks framework and am having trouble with mocking a class that has parameters in the constructor. The class function "Create" for TMock does not allow parameters. If try to create a mock instance of TFoo.Create( Bar:…
TDF
  • 125
  • 7
5
votes
1 answer

spring4d unregister interface type (spring4d, dunitx, delphi-mocks)

I am writing one of my first unit-tests using spring4d, dunitx and delphi-mocks. (spring4d Release 1.1 - 12.09.2014) In my testing application, I auto-wire-inject an interface to my System under test class (sut): IMyInterface = interface [{yes, a…
Markus
  • 357
  • 2
  • 13
5
votes
3 answers

Delphi Mocks – Is it possible to use ‘VAR’ or ‘OUT’ arrangements in a function that is been mocked with a ‘WillReturn’?

I have just started to use Delphi-Mocks with my dunit tests but it has little or no documentation. The Problem is: I am trying to write a test ‘Test_LogonUser_CheckPwd_GOOD_PASSWORD’ But I am not sure how to mock out the function …
Charles Faiga
  • 11,665
  • 25
  • 102
  • 139
4
votes
1 answer

How to use mocks in child classes in Delphi using Delphi-Mocks framework

Ok, I have been using the excellent Delphi-Mocks Framework and I just encountered a problem. Let´s suppose I have the following interfaces: IDepartment = Interface ['{F4915950-8F32-4944-A3B6-8E08F6C38ECC}'] function getID() : Integer; …
Luis Carrasco
  • 467
  • 3
  • 10
3
votes
1 answer

Is there a Spring4D correspondent function to WillReturnDefault

Delphi-Mocks has a WillReturnDefault method when you don't care about the parameters of a function. I can't figure out how to do that with Spring4D mocking. Grateful for help!
3
votes
1 answer

Using the Delphi Mock Framework and causing side effects

I am using the rather good Delphi Mocks Framework, and am trying to create a Mock of a class that contains a method that has 'side-effects', i.e. it is a read operation, and in the real-world implementation it sets the contents of a buffer, if the…
mmmm
  • 2,431
  • 2
  • 35
  • 56
2
votes
1 answer

Delphi DSharp Mock is throwing an Unexpected Invocation error - why?

When using record types in a Delphi DUnit test with DSharp Mock for an interface, it is throwing and Unexpected Invocation but I cannot figure out why? I have created test console app below. program ConsoleStuff; {$APPTYPE CONSOLE} {$R…
Rick Wheeler
  • 1,142
  • 10
  • 22
2
votes
0 answers

Delphi Mocks with class helper

I really like Delphi Mocks, but it seems to have a problem with class helpers. I have a class helper that extends TRESTResponse and want to test the functions I added. Unfortunately, this does not work. I have created the following simple…
Laurens
  • 325
  • 2
  • 12
2
votes
1 answer

Test in DUnitx with Delphi-Mocks passing private record

I am new to DUnitx and Delphi-Mocks so please be patient. The only other post I could find on this topic was 3 years old and not answered. Returning records in Delphi-Mocks Delphi Rio 10.3. Windows 10 I want to test this procedure: procedure…
Gary Shelton
  • 133
  • 1
  • 1
  • 9
2
votes
2 answers

EInvalidCast wih mock function returning a pointer type

I've written an interface to wrap the Windows Threadpool API and many of those functions return plain Pointer types. Now I'm writing tests and want to use the delphi-mocks framework to mock that wrapper interface. The problem is that the TMock setup…
user0042
  • 7,917
  • 3
  • 24
  • 39
2
votes
1 answer

How to verify multiple mock expectations with Delphi Mocks?

What is the difference between mock.verify and mock.verifyAll in Delphi Mocks? Does it verify expectations of other mocks as well? I want to verify all expectations of all my mocks created for the current unit test.
The Bitman
  • 1,279
  • 1
  • 11
  • 25
2
votes
2 answers

Delphi Mocks - Verify an overloaded method is never called

As the title suggests, I'm trying to write a test to verify that one version of a method is called, and that the overloaded version is not. Since Delphi-Mocks seems to use indexing on the parameter matching, I'm seeing a fail, and that the the…
mwilkinson
  • 97
  • 1
  • 7
2
votes
2 answers

Mocking interfaces in DUnit with Delphi-Mocks and Spring4D

So, I am getting Access Violation error when try to Mock 2-nd composite interface, below examples of code with using Delphi-Mocks and Spring4D frameworks unit u_DB; type TDBObject = class public property ID: TGUID; end; TDBCRM =…
SpanishBoy
  • 2,105
  • 6
  • 28
  • 51
2
votes
1 answer

How to check contents of parameters with Delphi Mocks Framework?

I'm trying to test with Delphi Mocks framework a class that creates simple value objects and passes them to a collaborator. How to check contents of these objects? General idea of the code is like this: TData = class Code : string; Field1 :…
Teloah
  • 58
  • 5
1
vote
1 answer

Delphi Mocks lifecycle in DUnit

I want to test the simplest case : testing a mocked strategy object. (look at : Strategy pattern). If I create a TMock in the TTestCase.setUp methods and store it in a TTestCase instance attribute, then should I free/NIL the mock variable in the…
The Bitman
  • 1,279
  • 1
  • 11
  • 25
1
2