1、创建python单元测试文件,包含test
文件名必须要包含test,否则将无法识别为unittest框架文件。
![图片[1] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012395757.png)
2、按Ctrl+Shift+p,打开vscode命令选板,输入命令“Python:Configure Tests”,然后回车,进入配置
![图片[2] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012404048.png)
3、如下选择框架
![图片[3] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012410464.png)
4、选择文件所在路径
![图片[4] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012414263.png)
5、选择文件的命名方式
![图片[5] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012420518.png)
6、打开控制台
![图片[6] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012422135.png)
7、可以看到控制台中已经包含了unittest方法
![图片[7] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012425498.png)
8、可以运行全部的测试案例,也可以只运行一个测试用例
![图片[8] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012432288.png)
9、结果显示如下
![图片[9] - vscode如何运行unittest框架? - 正则时光](https://www.regular.cc/wp-content/uploads/2023/11/2022082012472218.png)
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END