问题标签 [fakeit]
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.
c++ - 如何在使用模拟框架的谷歌测试延迟后测试调用
我目前正在尝试评估不同的测试框架。在使用模拟框架时(我倾向于 FakeIt,但 google mock 也很好),我知道您可以通过在调用函数之前和之后使用操作系统的计时器调用来滚动自己的“性能”测试来验证函数的性能。这不是我所追求的。
我所拥有的是在给定特定输入的情况下实现输出延迟的类。例如:
- 输入 1 从低到高
- 输出 1 在1.5 秒后从低电平变为高电平。
我希望能够做一些我指定边界的事情:
为澄清起见,不支持Before
和行。After
这只是我喜欢的简单语法的一个例子。
是否可以在进行输入调用和检查之前在窗口中实现“延迟”功能EXPECT_CALL
?
这是其中的一部分——我仍然需要启动一个专有计时器。像这样的东西?
nosql - 使用 Fakeit 生成数据
我正在使用 fakeit 来生成数据,但是当我输入命令“fakeit console user.yaml”时,我在下面得到了这个错误。我不知道问题是什么。
我在网上搜索了它,但我没有找到解决这个问题的方法。
我希望数据显示在控制台上,但我总是收到此错误。
c++ - Mocking an 3rd party library using fakeit
I am writing my own library/class that makes use of a 3rd party library. I want to write tests for my own class, and mock the 3rd party library. In one of the tests, I want to make sure that when a function on my class is being called, another function in the 3rd party library is also begin called as well. I though the FakeIt library would be a good idea to test this.
This is a sample of my testing code:
When this is run though, it throws a fakeit::SequenceVerificationException
with
So clearly, the mock didn't work and it's method wasn't called. Any idea how I can mock this class and verify that its method is being called?
MyTest.cpp just is just a simple test and will be my full library/class:
and it's header file:
ExternLib is a mock version of the 3rd party library. My implementation implements the bare necessities of the real interface, and the functions don't actually do anything. The implementation is actually basically just there to satisfy the #include Externlib.h
statements.
This is my Externlib.cpp:
and the header file:
c++ - 如何使用 gtest 在 C++ 中模拟非虚拟方法?
有没有一种简洁的方法可以用 gtest 在 c++ 中模拟非虚拟方法?尽管使用了强制你重新声明你的模拟类的 GoogleMock 方式。
在我看来,这个特性对于在 C++ 中充分发挥 BDD、TDD 和 mocking 的潜力是必不可少的。我目前正在使用FakeIt,但我仍然遇到这些困难:
- 无需使用虚拟方法即可测试代码
- 在不影响当前代码的情况下测试遗留代码
编辑:我发现Injector++和isolate++似乎是很好的解决方案,但不是跨平台的。
c++ - 在 C++ 中模拟没有依赖注入的函数内部创建的外部依赖对象
我正在尝试用 C++ 编写单元测试,并且面临使用 Fakeit 为外部依赖项创建模拟对象的问题。所以我们有一个类似于下面的类:
现在假设我想为test_method()
class编写一个单元测试A
。当我们打电话时,obj.sendInt()
我想模拟它并返回一个不同的值。我尝试使用 fakeit 但无法找到解决方案。
我知道如果我们尝试B
通过构造函数或 setter 方法进行依赖注入,这将得到解决,但我不想这样做,因为它需要对A
.
对于 Java 中的类似场景,我会使用 PowerMockito 并使用PowerMockito.whenNew