简体   繁体   English

使用增强单元测试来测试exit()

[英]Test exit() with boost unit tests

我想问一下,是否可以通过Boost Unit Test库测试exit()或测试返回代码?

There is BOOST_CHECK_THROW() to verify that an exception (of a certain type) is thrown. 有BOOST_CHECK_THROW()来验证是否抛出了某种类型的异常。 You usually shouldn't be calling exit() in your library code at all--throw exceptions and let the higher levels of the call stack decide whether to exit or not. 通常,您根本不应该在库代码中完全调用exit()-引发异常,并让更高级别的调用堆栈决定是否退出。

Boost Test expects to be able to control the "main" application itself, so if you call exit() I'm not really sure what you would want Boost Test to do next. Boost Test期望能够控制“主”应用程序本身,因此,如果您调用exit(),我不太确定您接下来想要Boost Test做什么。 Trap the exit() call and not let the program exit? 捕获exit()调用而不让程序退出? What if your library actually depended on exit() working normally? 如果您的库实际上依赖于exit()正常工作怎么办?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM