I am building unit testing of the application that uses os.Exit(1), once os.Exit(1) executes remaining test file are skipped with go test, I am thinking about suppressing os.Exit during the unit test execution only. I wonder how I can determine that app has been bootstrap from go test runner?
1条回答 默认 最新
- duanpai1033 2018-02-10 00:52关注
You will find various ways to unit test method with os.Exit() in "Testing
os.Exit
scenarios in Go with coverage information (coveralls.io/Goveralls)".It uses a function which is:
-
os.Exit()
when you are not testingvar osExit = os.Exit
-
and "yourOsExit" when you are testing.
func TestCrasher(t *testing.T) { // Save current function and restore at the end: oldOsExit := osExit defer func() { osExit = oldOsExit }() osExit = myExit
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报 -
悬赏问题
- ¥15 腾讯IOA系统怎么在文件夹里修改办公网络的连接
- ¥15 filenotfounderror:文件是存在的,权限也给了,但还一直报错
- ¥15 MATLAB和mosek的求解问题
- ¥20 修改中兴光猫sn的时候提示失败
- ¥15 java大作业爬取网页
- ¥15 怎么获取欧易的btc永续合约和交割合约的5m级的历史数据用来回测套利策略?
- ¥15 有没有办法利用libusb读取usb设备数据
- ¥15 为什么openeluer里面按不了python3呢?
- ¥15 关于#matlab#的问题:训练序列与输入层维度不一样
- ¥15 关于Ubuntu20.04.3LTS遇到的问题:在安装完CUDA驱动后,电脑会进入卡死的情况,但可以通过键盘按键进入安全重启,但重启完又会进入该情况!