2

我正在尝试实现基于 QT 状态机的工作流程,并且出于测试目的,我正在尝试使用 QTest 播放我的工作流程。

void initTestCase()
{    

    machine = loadScxmlFile("StateMachine.scxml");
    machine->start();

    auto wrapper = new Wrapper(machine);
    wrapper->connect();

    qDebug() << "machinestate" << wrapper->getmachineState();
    qDebug() << "activeStateBefore" << wrapper->getmachineState();
    wrapper->initialize();
    qDebug() << "activeStateAfter" << wrapper->getmachineState();
}

但可悲的是,即使我正确加载了我的 scxml,即使它看起来正在运行和初始化,active_state 始终是空的。

Config: Using QtTest library 5.9.0, Qt 5.9.0 (x86_64-little_endian-llp64 shared (dynamic) release build; by MSVC 2015)
QDEBUG : TestXImagerMock::initTestCase() machinestate ()
QDEBUG : TestXImagerMock::initTestCase() activeStateBefore ()
QDEBUG : TestXImagerMock::initTestCase() activeStateAfter ()
PASS   : TestXImagerMock::initTestCase()

当我尝试使用正确的 QCoreApplication 时,一切看起来都很迷人,所以问题似乎来自 QTEST_MAIN

QCoreApplication testapplication(argc, nullptr);
testapplication.exec();

QDEBUG : TestXImagerMock::initTestCase() onEntry_NotInitialized
QDEBUG : TestXImagerMock::initTestCase() onEntry_NotInitialized
QDEBUG : TestXImagerMock::initTestCase() onEntry_Initializing

但是那些日志是在testapplication.exec()被调用之后出现的。

我是否需要添加一些东西才能在 QTest 创建的 QCoreApplication 中具有相同的行为?

谢谢 !

4

0 回答 0