jpo38
jpo38

Reputation: 21514

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

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).

Upvotes: 0

Views: 320

Answers (2)

Raffi
Raffi

Reputation: 3385

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

Upvotes: 0

piwi
piwi

Reputation: 5336

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

Upvotes: 2

Related Questions