paulojfonseca
paulojfonseca

Reputation: 51

Google Test Gmock - Mocking Class Templates, trouble on EXPECT_CALL

Trying to implement Unit tests for a Class Template with Gtest and Gmock, but having some troubles with EXPECT_CALL.

My Abstract Class:

#pragma once

template <class T>
class AbstractMessageQueue {
   public:
    virtual ~AbstractMessageQueue() {}
    virtual T dequeue() = 0;
}

My MockClass: mocks/MockMessageQueue.hpp

#include <gmock/gmock.h>
#include "AbstractMessageQueue.hpp"

template <class T>
class MockMessageQueue : public AbstractMessageQueue<T> {
   public:
    MockMessageQueue(){}
    ~MockMessageQueue(){}

    MOCK_METHOD(T, dequeue, (), (override));
}

My Test:

#include <gmock/gmock.h>
#include <gtest/gtest.h>

#include "./mocks/MockMessageQueue.hpp"

using ::testing::StrictMock;

namespace my {
namespace project {
namespace {

class TestFixture : public ::testing::Test {
    public: 
       StrictMock<MockMessageQueue<int>> a{};
       AbstractMessageQueue<int>& queue = a ;
};

TEST_F(TestFixture, test1){
    
    EXPECT_CALL(queue, dequeue()).Times(1);  //!!ERROR error: ‘class AbstractMessageQueue<int>’ has no member named ‘gmock_dequeue’; did you mean ‘dequeue’? 
    
    queue.dequeue();

}

}}}

I get the following compilation error on the EXPECT_CALL line:
error: ‘class AbstractMessageQueue<int>’ has no member named ‘gmock_dequeue’; did you mean ‘dequeue’?

I cannot figure out what is the problem here. If I comment the line with EXPECT_CALL i can make the test compile, and it will fail because of:
Uninteresting mock function call - returning default value.
Which in my view means the Mock is indeed working and the failure is caused by the StrickMock

Can someone shine some light? Thanks

Upvotes: 0

Views: 815

Answers (1)

3CxEZiVlQ
3CxEZiVlQ

Reputation: 38539

EXPECT_CALL expects the mock object.

EXPECT_CALL(queue, dequeue()).Times(1);

should be

EXPECT_CALL(a, dequeue());

.Times(1) is odd and removed.

Upvotes: 2

Related Questions