【发布时间】:2012-11-09 16:56:17
【问题描述】:
我正在做一个python Command-Line-Interface程序,做测试时觉得很无聊,例如,这里是程序的帮助信息:
usage: pyconv [-h] [-f ENCODING] [-t ENCODING] [-o file_path] file_path
Convert text file from one encoding to another.
positional arguments:
file_path
optional arguments:
-h, --help show this help message and exit
-f ENCODING, --from ENCODING
Encoding of source file
-t ENCODING, --to ENCODING
Encoding you want
-o file_path, --output file_path
Output file path
当我对程序进行更改并想测试某些东西时,我必须打开一个终端,
输入命令(带有选项和参数),输入回车,看看是否出现任何错误
在跑步的时候。如果真的发生错误,我必须回到编辑器并检查代码
从头到尾,猜测 bug 的位置,做些小改动,写print 行,
返回终端,再次运行命令...
递归。
所以我的问题是,用 CLI 程序进行测试的最佳方法是什么,是否可以这么简单 作为使用普通 python 脚本的单元测试?
【问题讨论】:
标签: python unit-testing testing command-line-interface