Reputation: 313
Is it possible to write unit tests for Qt application for example QCoreApplication to test it's functions that are invoked in arbitrary time? Let's suppose that I want to test member function of my class like
void deleteConnectionFromList(QTcpSocket*);
This function should be called after other functions like addNewSocket()
But where should I put BOOST_CHECK_EQUAL() statement?
BOOST_AUTO_TEST_CASE( test )
{
int argc{};
QCoreApplication app(argc, nullptr);
Server server;
app.exec();
}
Upvotes: 1
Views: 728
Reputation: 11
I needed to use boost unit test with Qt Network classes (which required event loop). What I did is something like that.
BOOST_AUTO_TEST_CASE(createServerNetwork)
{
QCoreApplication app(boost::unit_test::framework::master_test_suite().argc,
boost::unit_test::framework::master_test_suite().argv);
std::thread thread_server( [&](void)
{
[...]//your code here
QCoreApplication::quit();
});
BOOST_CHECK(app.exec() == 0);
thread_server.join();
}
Upvotes: 1