'How can I test method calling QMetaObject::invokeMethod with Qt::QueuedConnection -- using gtest gmock framework
Suppose I have a method and I want to test it using gtest/gmock framework. This method calls another method inside itself using a Qt queued invoke:
void MyClass::handleFoo()
{
// ...
Q_ASSERT(QMetaObject::invokeMethod(this, "handleBar", Qt::QueuedConnection));
}
void MyClass::handleBar()
{
_view.show();
}
TEST_F(MyTestSuite, MyTest)
{
EXPECT_CALL(_viewMock, show()); // Fails with never called
emit _myClassObj->foo();
// Tried QCoreApplication::processEvents() -- does not help
}
Is there any way to do it? I think maybe I should just test these two handlers separately. But how can I test that the method handleFoo() will indeed call handleBar()?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
