.


:




:

































 

 

 

 


QtTestLib ++ Qt.

5.2

Unit testing i i (, i, ) i i. i: i i , i i i i . i: i i i i i , i, i .

Qt QtTestLib, , . "" .

5.2.1 QT

. , .

: , . , . ³ : (25, 0), (-12, -15), (2007, 2007) (-12, 5). , , . , . :

- ' Test. : MyClass, Test_MyClass;

- () .

 

#include <QtTest>

#include "MyClass.h"

 

class Test_MyClass: public QObject {

Q_OBJECT

private slots:

void min();

void max();

};

 

 

void Test_MyClass::min()

{

MyClass myClass;

QCOMPARE(myClass.min(25, 0), 0);

QCOMPARE(myClass.min(-12, -5), -12);

QCOMPARE(myClass.min(2007, 2007), 2007);

QCOMPARE(myClass.min(-12, 5), -12);

}

 

void Test_MyClass::max()

{

MyClass myClass;

QCOMPARE(myClass.max(25, 0), 25);

QCOMPARE(myClass.max(-12, -5), -5);

QCOMPARE(myClass.max(2007, 2007), 2007);

QCOMPARE(myClass.max(-12, 5), 5);

}

 

QTEST_MAIN(Test_MyClass)

#include "test.moc"

 

, min() max() MyClass. QTest. QObject , , QObject. , private.

QCOMPARE() , . , .

main, . , , Qt QTEST_MAIN().

, .

ϳ .

 

#ifndef MyClass_h_

#define MyClass_h_

 

class MyClass {

public:

int min(int n1, int n2)

{

return n1 < n2? n1: n2;

}

 

int max(int n1, int n2)

{

return n1 > n2? n1: n2;

}

};

#endif //MyClass_h_

 

MyClass .

 

SOURCES = test.cpp

HEADERS = MyClass.h

CONFIG += qtestlib

win32:TARGET =../TestLib

 

pro-, config qttest. ' , - . , , . , , . min() max() MyClass . . ' :

 

********* Start testing of Test_MyClass *********

Config: Using QTest library 4.7.4, Qt 4.7.4

PASS: Test_MyClass::initTestCase()

FAIL!: Test_MyClass::min() Compared values are not the same

Actual (myClass.min(25, 0)): 25

Expected (0): 0

Loc: [../TestLib/test.cpp(24)]

FAIL!: Test_MyClass::max() Compared values are not the same

Actual (myClass.max(25, 0)): 0

Expected (25): 25

Loc: [../TestLib/test.cpp(34)]

PASS: Test_MyClass::cleanupTestCase()

Totals: 2 passed, 2 failed, 0 skipped

********* Finished testing of Test_MyClass *********

 

initTestCase() cleanupTest() . ֳ -. . , , : "FAIL!", "Test_MyClass::min()" "Test_MyClass::max()", (Actual) (Expected). , , - . MyClass , . . :

 

********* Start testing of Test_MyClass *********

Config: Using QTest library 4.7.4, Qt 4.7.4

PASS: Test_MyClass::initTestCase()

PASS: Test_MyClass::min()

PASS: Test_MyClass::max()

PASS: Test_MyClass::cleanupTestCase()

Totals: 4 passed, 0 failed, 0 skipped

********* Finished testing of Test_MyClass *********

 

, .

 

QCOMPARE(). . QtTestLib . , . , . , , _data.

 

class Test_MyClass: public QObject {

Q_OBJECT

private slots:

void min_data();

void max_data();

 

void min();

void max();

};

 

: min_data() max_data(), .

 

void Test_MyClass::min_data()

{

QTest::addColumn<int>("arg1");

QTest::addColumn<int>("arg2");

QTest::addColumn<int>("result");

 

QTest::newRow("min_test1") << 25 << 0 << 0;

QTest::newRow("min_test2") << -12 << -5 << -12;

QTest::newRow("min_test3") << 2007 << 2007 << 2007;

QTest::newRow("min_test4") << -12 << 5 << -12;

}

 

min_data() . QTest: addColumn(). ϳ QTest:: newRow(). , , . , : min().

 

void Test_MyClass::max_data()

{

QTest::addColumn<int>("arg1");

QTest::addColumn<int>("arg2");

QTest::addColumn<int>("result");

 

QTest::newRow("max_test1") << 25 << 0 << 25;

QTest::newRow("max_test2") << -12 << -5 << -5;

QTest::newRow("max_test3") << 2007 << 2007 << 2007;

QTest::newRow("max_test4") << -12 << 5 << 5;

}

 

max_data() min_data(). .

 

void Test_MyClass::min()

{

MyClass myClass;

QFETCH(int, arg1);

QFETCH(int, arg2);

QFETCH(int, result);

 

QCOMPARE(myClass.min(arg1, arg2), result);

}

 

, min() - . QFETCH() arg1, arg2, result . , ' ' , ' , . QCOMPARE(). .

 

void Test_MyClass::max()

{

MyClass myClass;

QFETCH(int, arg1);

QFETCH(int, arg2);

QFETCH(int, result);

 

QCOMPARE(myClass.max(arg1, arg2), result);

}

 

max() min() , MyClass:: max() MyClass:: min().

 

, main() QTESTMAIN() , :

 

QTEST_MAIN(Test_MyClass)

#include "test.moc"

 

5.2.3

QTestLib . , QLineEdit. , .

edit() QLineEdit. "ABCDEFGH", QTest:: keyClicks(), . ' , , , . QTest , 䳿 , .

 

#include <QtTest>

#include <QtGui>

 

//

class Test_QLineEdit: public QObject {

Q_OBJECT

private slots:

void edit();

};

 

 

void Test_QLineEdit::edit()

{

QLineEdit txt;

QTest::keyClicks(&txt, "ABCDEFGH");

 

QCOMPARE(txt.text(), QString("ABCDEFGH"));

QVERIFY(txt.isModified());

}

 

QTEST_MAIN(Test_QLineEdit)

#include "test.moc"

 

QCOMPARE() , . ϳ , isModified() true. QVERIFY(). , , . .

, . QObject. QTESTMAIN(), main() .

QCOMPARE() . , , - .

QVERIFY() . true, . , .

, ' , QtTestLib . - private . , , _data. . QFETCH() .

QtTestLib .

1.3.1 QtTestLib.

1.3.2 C++ QtTestLib , '- ( ).

1.3.3 .

1.3.4 .

1.4

1.4.1 .

1.4.2 , ++.

1.4.3 .

1.4.5. , .

 


 

˳

 

1. Bevan N. Specifying and Measuring Quality in Use // Proceedings of the 22nd international conference on Software engineering, 2000. P. 322331.

2. Halpern M. Addressing Quality Risk in Collaborative Automotive Design: Commentary, Gartner Group, 2001. P. 262293.

3. Hassenzahl M., Platz A., Burmester M., Lehner K. Hedonic and Ergonomic Quality Aspects Determine a Software's Appeal // Proceedings of the CHI 2000 conference on Human factors in computing systems, 2000. P. 193201.

4. Hutcheson M. L. Software Testing Fundamentals: Methods and Metrics. John Wiley & Sons. 2003. 408 p.

5. IEEE Standard for a Software Quality Metrics Methodology Copyright , Institute of Electrical and Electronics Engineers, Inc. 2005.

6. Kan H.N. Metrics and Models in Software Quality Engineering, Second Edition, 2002. 560 p.

7. Pandian C. R. Software Metrics: A Guide to Planning, Analysis, and Application Auerbach Publications, 2004. 312 p.

8. ., . Java 2. , 1. , 7- . : "", 2006. 896.

9. ., . Java 2. , 2. , 7- . : "", 2006. 1168.

 



<== | ==>
Wieczornica ku czci ks. J. Popiełuszki |
:


: 2016-12-06; !; : 282 |


:

:

, .
==> ...

1757 - | 1539 -


© 2015-2024 lektsii.org - -

: 0.046 .