如何使用 Python 和 PyQt 对我的 GUI 程序进行单元测试? [英] How do I unit testing my GUI program with Python and PyQt?

查看:37
本文介绍了如何使用 Python 和 PyQt 对我的 GUI 程序进行单元测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说单元测试是保持代码正常工作的好方法.

I heard Unit Testing is a great method to keep code working correctly.

单元测试通常将一个简单的输入放入一个函数,并检查它的简单输出.但我如何测试 UI?

The unit testing usually puts a simple input to a function, and check its simple output. But how do I test a UI?

我的程序是用 PyQt 编写的.我应该选择 PyUnit,还是 Qt 内置的 QTest?

My program is written in PyQt. Should I choose PyUnit, or Qt's built-in QTest?

推荐答案

有一个关于使用 Python 的单元测试框架和 QTest 的很好的教程 这里.

There's a good tutorial about using Python's unit testing framework with QTest here.

这不是关于选择一个或另一个.相反,它是关于将它们一起使用. QTest 的目的只是模拟击键、鼠标点击和鼠标移动.Python 的单元测试框架会处理其余的工作(设置、拆卸、启动测试、收集结果等).

It isn't about choosing one or the other. Instead, it's about using them together. The purpose of QTest is only to simulate keystrokes, mouse clicks, and mouse movement. Python's unit testing framework handles the rest (setup, teardown, launching tests, gathering results, etc.).

这篇关于如何使用 Python 和 PyQt 对我的 GUI 程序进行单元测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆