利用google test 与QTest进行GUI 测试
Jingwenlai 2009-11-10
Google test写测试用例非常方便,而且相对于QTest来说,提供了更多的比较宏,但其并未提供测试GUI的方法,相反,Qt Test lib虽然仅提供了QCOMPARE等少数的宏,但QtTest提供了诸如keyClick,keyClicks,mouseClicks,mouseClick等模拟UI行为的测试方法。可以将两者结合起来对QT的GUI程序进行测试,同时,也能够利用Google Test的便利性来写测试程序。 please refer to QtAssitant.exe for more informations about QtTest lib.
下面是一个示例程序
这个示例完成如下功能,根据用户的输入对显示的值进行增减。
执行了五个测试,其中一个是初始化测试,另外两个是正常情况的测试,还有两种情况是极端情况的测试。
以下是测试代码/**Testing Code;*/
#ifndef TEST_PANELITEM_HPP
#define TEST_PANELITEM_HPP
#include <gtest/gtest.h>
#include "PanelItem.h"
#include <QtTest/QtTest> //for testing Gui
#include <QString>
class GPanelItemTest : public ::testing::Test
{
protected:
virtual void SetUp()
{
panelItem = new GPanelItem();
利用google test 与QTest进行GUI 测试
最新推荐文章于 2025-02-15 15:13:27 发布