问题标签 [delphi-mocks]
For questions regarding programming in ECMAScript (JavaScript/JS) and its various dialects/implementations (excluding ActionScript). Note JavaScript is NOT the same as Java! Please include all relevant tags on your question; e.g., [node.js], [jquery], [json], [reactjs], [angular], [ember.js], [vue.js], [typescript], [svelte], etc.
delphi - Delphi Mocks - 验证从不调用重载方法
正如标题所示,我正在尝试编写一个测试来验证方法的一个版本是否被调用,而重载版本不是。由于 Delphi-Mocks 似乎在参数匹配上使用索引,我看到失败,并且实际上调用了重载函数,而不是。
样例测试接口
示例测试代码
谢谢!
delphi - Delphi 在 DUnit 中模拟生命周期
我想测试最简单的情况:测试模拟策略对象。(看:策略模式)。
TMock<T>
如果我在方法中创建 aTTestCase.setUp
并将其存储在TTestCase
实例属性中,那么我应该释放/NILtearDown
方法中的模拟变量吗?
mock := NIL
不编译:
[dcc32 错误] TestUnit2.pas(44):E2010 不兼容的类型:“Delphi.Mocks.TMock<T>”和“指针”。
运行没有任何错误,mock.free
但我不确定我应该调用它。当进程退出其范围(在测试用例析构函数之后)时释放的模拟。
我应该打电话/设置什么吗?
编码:
单元2.pas:
测试单元2.pas:
delphi - 如何使用 Delphi Mocks 验证多个模拟期望?
Delphi Mocks 中的 mock.verify 和 mock.verifyAll 有什么区别?它是否也验证了其他模拟的期望?我想验证为当前单元测试创建的所有模拟的所有期望。
delphi - 列表.count 使用 Delphi Mocks 模拟返回值
在我的单元测试中,需要设置一个模拟的TList<T>
. 如何为TList<T>.count
读取的模拟属性设置返回值?
当我使用count
后When
编译器错误信息是:
当我使用getCount
后When
编译器错误信息是:
count
属性直接读取fCount
属性。有什么解决办法吗?
delphi - 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 interface takes a TValue
object to specify a default return value for the mocked functions and I can't see a way how to do that correctly from the available TValue
functions. Though I've seen that ekPointer
is a valid TTypeKind
value.
When the mocked function is called I receive an EInvalidCast
exception from the corresponding RTTI invocation.
That happens specifically, when the RTTI invocation tries to cast the return type value from the implicit TValue
object.
My code looks roughly like this1:
the class under test
and the testing stuff
TL;DR;
So the question is:
What do I need to do that TValue
is created properly to contain a PTP_POOL
pointer type?
1)It's a bit too much code to setup a MCVE, so I just sketch it here to give you the background, see the {**** highlighted comments ****}
delphi - 是否有与 WillReturnDefault 对应的 Spring4D 对应函数
WillReturnDefault
当您不关心函数的参数时,Delphi-Mocks有一个方法。我不知道如何使用Spring4D 模拟来做到这一点。感谢帮助!
delphi - 使用 Delphi-Mocks 通过私有记录在 DUnitx 中进行测试
我是 DUnitx 和 Delphi-Mocks 的新手,所以请耐心等待。我能找到的关于这个主题的唯一其他帖子是 3 岁且没有回答。在 Delphi-Mocks 中返回记录
德尔福里约 10.3。视窗 10
我想测试这个过程:
接口和记录类型声明为:
我在受保护部分有通知程序
在我的测试项目中,我有一个后代类
所以我可以调用受保护的方法。到目前为止我所拥有的不起作用,因为我无法从 TdmMariaDBConnection 提供私有记录实例,而现在只关注 MainViewModel。
显然添加 LCommandRecord 是错误的,我只是添加它们以使其编译。我需要(我认为)设置中测试类的记录实例。我尝试添加一个函数来获得它,但它也不起作用。
测试甚至没有完成,我在 TestInsight GUI 中得到一个不完整的圆圈,而不是希望的绿色检查。
任何帮助,将不胜感激。这也是验证的正确用法吗?我只能找到通过时什么都不做的解释,那么如何添加Assert?
提前感谢加里
unit-testing - Delphi Mocks 与类助手
我真的很喜欢 Delphi Mocks,但它似乎对类助手有问题。我有一个扩展 TRESTResponse 的类助手,并想测试我添加的函数。不幸的是,这不起作用。我创建了以下简单的复制:
模拟 MyFunc1 按预期工作,但无法模拟 MyFunc2。第二个 LMock.Setup.WillReturn-line 引发异常[MyClass] already defines Will Return When for method [MyFunc1]
。如果您删除模拟设置,MyFunc1
则不会引发异常,但MyFunc2
不会被模拟。
任何建议如何解决这个问题?还是不能用 Delphi Mocks 模拟类助手?
delphi - Delphi DSharp Mock 抛出意外调用错误 - 为什么?
在带有 DSharp Mock 的 Delphi DUnit 测试中使用记录类型作为接口时,它正在抛出和意外调用,但我不知道为什么?我在下面创建了测试控制台应用程序。
测试可以使用“WhenCallingWithAnyArguments”方法,但我真的需要“WhenCalling”方法来检查分配给属性设置器的值。
我将 Nullable<> 类型仅用于演示目的,其他 Record 类型也失败了。
请帮忙!