1

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();

}
Miszo97
  • 303
  • 2
  • 11
  • It would be a thousand times more convenient to use [Qt Test](https://doc.qt.io/qt-5/qtest-overview.html) than any other testing framework with Qt. – Dmitry May 28 '18 at 07:23
  • I don't know BOOST auto test framework but I doubt you should instantiate the app in the core of the test, it should be done in the set up. – sandwood May 30 '18 at 08:55

1 Answers1

1

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();
}
Yannick
  • 11
  • 2