How do I make Visual Studio pause after executing

2019-01-16 05:42发布

I have a collection of Boost unit tests I want to run as a console application.

When I'm working on the project and I run the tests I would like to be able to debug the tests, and I would like to have the console stay open after the tests run.

I see that if I run in release mode the console window stays up after the program exits, but in debug mode this is not the case.

I do not want to add 'system("pause");' or any other hacks like reading a character to my program. I just want to make Visual Studio pause after running the tests with debugging like it would if I were running in release mode. I would also like it if the output of tests were captured in one of Visual Studio's output windows, but that also seems to be harder than it should be.

How can I do this?

16条回答
闹够了就滚
2楼-- · 2019-01-16 06:40

Set a breakpoint on the last line of code.

查看更多
\"骚年 ilove
3楼-- · 2019-01-16 06:40

Or you could use boost_test "Test Log Output."

http://www.boost.org/doc/libs/1_47_0/libs/test/doc/html/utf/user-guide/test-output/test-log.html

Then it won't matter whether the console window shows up at all AND your build logging can preserve the unit testing output as an artifact for examination on failed builds...

查看更多
何必那么认真
4楼-- · 2019-01-16 06:41

I would use a "wait"-command for a specific time (milliseconds) of your own choice. The application executes until the line you want to inspect and then continues after the time expired.

Include the <time.h> header:

clock_t wait;

wait = clock();
while (clock() <= (wait + 5000)) // Wait for 5 seconds and then continue
    ;
wait = 0;
查看更多
倾城 Initia
5楼-- · 2019-01-16 06:41

Just use a logging library, like log4net, and have it log to a file appender.

查看更多
登录 后发表回答