向已经饱和的另一个添加另一个EXPECT_CALL

问题描述 投票:0回答:1

让我们考虑一下这样的gmock代码:

using namespace ::testing;
struct TestSuite : Test
{
    StrictMock<DependencyMock> dependency;

    void expectCallingDependency()
    {
        EXPECT_CALL(dependency, call());
    }

    SomeSut sut{dependency};
};

TEST_F(TestSuite, shouldCallDependencyTwice)
{
    expectCallingDependency();

    sut.someAction1(); //calls dependency.call() inside

    expectCallingDependency();

    sut.someAction2(); //calls dependency.call() also
}

我遇到这样的错误:

Mock function called more times than expected - returning directly.
    Function call: call()
         Expected: to be called once
           Actual: called twice - over-saturated and active

Actual function call count doesn't match EXPECT_CALL(dependency, call())...
         Expected: to be called once
           Actual: never called - unsatisfied and active

我知道它仍然尝试匹配第一个EXPECT_CALL,所以我添加了RetiresOnSaturation,但没有效果:

    Expected: the expectation is active
           Actual: it is retired
         Expected: to be called once
           Actual: called once - saturated and retired

    Actual function call count doesn't match EXPECT_CALL(dependency, call())...
         Expected: to be called once
           Actual: never called - unsatisfied and active

但是,使用RetiresOnSaturation()并在调用expectCallingDependency()之前移动第二个sut.someAction1()使一切正常-但是我希望在someAction1()之后有这个期望,因为在期望之上,它不强制执行someAction1()调用一次

c++ googletest googlemock
1个回答
0
投票

它对我有用。问题可能出在其他地方。

© www.soinside.com 2019 - 2024. All rights reserved.