Author : Tao Xia
Date: 2009-3-17
1. Basic Method About QTestLib
=====================================
(1) QT += testlib, #include <QTest>
(2) A class inherite from QObject.
(3) slots function to hold test content.
(4) Data_Driven function.
void QTestClass::funcName()
{
QFETCH(Type, Name);
QFETCH(Type, Name2);
...
}
void QTestClass::funcName_data()
{
QTest::addColumn<Type>("Name");
QTest::addColumn<Type>("Name2");
...
QTest::newRow("Description")<< value1 << value2 << ...
QTest::newRow("Description")<< value1 << value2 << ...
}
2. QTestLib example in PhoneAPI UT.
=====================================
(1) Project File, the files including problem.
(2) On-Off, condition select.
(3) Test data preparation.
(4) Completely auto test.
3. GUI Test
=====================================
QTest::keyClicks() //KeyAction
QTest::keyClicks(myWidget, "hello world");
QTest::keyClick(myWidget, Qt::Key_Escape, Qt::ShiftModifier, 200);
void QTest::mouseClick ( QWidget * widget, Qt::MouseButton button,Qt::KeyboardModifiers modifier = 0, QPoint pos = QPoint(), int delay= -1 )
void TestGui::testGui() {
QLineEdit lineEdit;
QTest::keyClicks(&lineEdit, "hello world");
QCOMPARE(lineEdit.text(), QString("hello world"));
}
4. Stub
=====================================
在计算机软件中,stub表示一小段特殊代码.主要起到承上启下的作用或者提示作用.下面是glibc手册中相关内容的描述:
http://www.gnu.org/software/libc/manual/html_node/Porting.html
----
If it is possible to implement the routines in a generic file in machine-independent C, using only other machine-independent functions in the C library, then you should do so. Otherwise, make them stubs. A stub function is a function which cannot be implemented on a particular machine or operating system. Stub functions always return an error, and set errno to ENOSYS (Function not implemented). See Error Reporting. If you define a stub function, you must place the statement stub_warning(function), where function is the name of your function, after its definition; also, you must include the file <stub-tag.h> into your file. This causes the function to be listed in the installed <gnu/stubs.h>, and makes GNU ld warn when the function is used.
5. Unit Test
=====================================
http://msdn.microsoft.com/en-us/magazine/cc163665.aspx
http://www.ibm.com/developerworks/cn/java/j-test/
http://www.miiceic.org.cn/phrase/200602281036115.html