Comments (4)
/tldr
Short answer, no.
Long answer, I wish it could be.
/explanation /rant
I really wanted to implement this feature. However as Delphi's parameter calling is undefined behaviour, I couldn't.
The goal syntax was the following, and can be seen in f-param-matches branch.
mock.Setup.WillReturn(TValue.From(true)).When.DoIt(Is.Any(), Is.Any());
As a result development has stalled a bit. I consider this to be a critical feature of a Mocking framework. The only other way I can see it implemented is via using text names of the functions, and procedures passing an array of parameter values.
mock.Setup.WillReturn(TValue.From(true)).When("DoIt", [Is.Any(), Is.Any()]);
The problem I have with this is that its not caught at compile time. Tests should break as early as possible. If the interface has changed, then the test should break in compile as it has not been updated. It will still break, but much later when the tests are actually run.
Another point to this is that maintenance is harder. The IDE knows nothing about the text passed to the When function being an actual function/procedure. So when IDE plugins look for usages of an interface, this test would not appear in that list.
So, when I or someone else gets some spare time we might implement the text version for starters until we think of something better. Better have a functional framework, rather than it being incomplete. I think the wind was taken out of our sails when we found the undefined behaviour (which we could see no real good reason for).
from delphi-mocks.
Thank you very much for this answer, whilst it doesn't enable me to do what I need to do (yet), it is very detailed and explains the situation properly.
from delphi-mocks.
This has been implemented in pr #64. The way I got around the undefined order of parameter execution was to simply define it when the matcher was called. This has lead to It being defined as a function now.
e.g.
It(0).IsAny()
The above example will match the first parameter. This means you could have the following;
e.g.
mock.Setup.WillReturn(8).When.TakesTwoParams(It(0).IsAny(), It(1).IsEqualTo(false));
Note that this means you can still get errors by incorrectly indexing the matches.
e.g.
mockCredit.Setup.WillReturn(8).When.TakesTwoParams(It(1).IsAny(), It(0).IsEqualTo(false));
If people could work on the param matcher branch and give me some feedback that would be great. If not, might just merge it.
from delphi-mocks.
So param matchers have been implemented and merged into master. I am marking this issue resolved.
from delphi-mocks.
Related Issues (20)
- Some questions rather than an issue HOT 3
- Get rid of W1029 warning in Delphi compile mode HOT 4
- Need research if IStubSetup<T> can benefit from an overloaded method function WillReturn<TReturn>(const value : TReturn) : IWhen<T>; overload; HOT 2
- Memory leak there should not have memory leak HOT 2
- Typos in Sample1Main.pas HOT 1
- Status of Delphi XE support HOT 2
- Mocking an empty interface HOT 2
- TObjectProxy.Destroy raises "Invalid pointer operation". HOT 1
- Typo on Delphi.Mocks.Proxy.pas
- Some units have (apparently unnecessarily) Windows in the uses clause HOT 3
- Mock Objects HOT 1
- Remove copy of VSoft.WeakReference and use dpm package
- [discussion] Delphi Mock documentation HOT 7
- TMock<IMyInterface>.MyMethod(X) leads to access violation when X is a record type HOT 3
- Test fails with current version of Mocks, passes with old version HOT 2
- Calling virtual method with defined behavior can cause problems HOT 2
- Example code does not work HOT 1
- Not able to define behaviour for overloaded functions with different parameters. HOT 1
- WillReturn for public class property with private getter HOT 4
- Call to actual class method when mocking class with a non-virtual method HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from delphi-mocks.