How can I force boost::unit_test to pause after test is completed?

306 views Asked by At

When running console programs from Visual Studio, the console shows, program runs and then console disappears without giving you a chance to see it.

In general, I add those lines before main's return statement:

std::cout << "Press enter to exit " << std::endl;
std::string sGot;
getline(std::cin, sGot);

How can I do something similar when program is compiled with boost::unit_test framework? As the main is directly part of the boost library, I can't modify it (I'd like to avoid recompiling boost for that).

2

There are 2 answers

0
piwi On

You can add a test that is dedicated to this purpose and is always run last.

Edit (completed by jpo38):

BOOST_AUTO_TEST_SUITE( PauseWhenDone )

BOOST_AUTO_TEST_CASE( do_pause )
{
    std::cout << "Press enter to exit " << std::endl;
    std::string sGot;
    getline(std::cin, sGot);
}


BOOST_AUTO_TEST_SUITE_END()
1
Raffi On

This is a Visual Studio preference:

  • go to Menu > Tools > Options, you see the option dialog like the image below
  • navigate to "Debugging"
  • Uncheck "Automatically close the console when debugging stops"

enter image description here