В общем, я решил освоить юнит тесты.
Вот примерный код тестов.
test_myclass.h
#ifndef TEST_MYCLASS_H
#define TEST_MYCLASS_H
#include <QTest>
class Test_MyClass : public QObject {
Q_OBJECT
private slots:
void min();
void max();
};
QTEST_MAIN(Test_MyClass)
#include "test_myclass.moc"
#endif // TEST_MYCLASS_H
#include "test_myclass.h"
#include "myclass.h"
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);
}
#ifndef MYCLASS_H
#define MYCLASS_H
class MyClass {
public:
MyClass();
int min(int n1, int n2);
int max(int n1, int n2);
};
#endif // MYCLASS_H
#include "myclass.h"
MyClass::MyClass() {
}
int MyClass::min(int n1, int n2) {
return n1 < n2 ? n1 : n2;
}
int MyClass::max(int n1, int n2) {
return n1 > n2 ? n1 : n2;
}
:-1: error: No rule to make target 'test_myclass.moc', needed by 'main.o'. Stop.
Теме 100 лет, но всё же отвечу. В хедер нельзя мок инкюдить
Форум Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)