I need to make some unit test for my school project in Qt and although I have read Qt tutorial on that I can't figure out how am I supposed to write such tests. All of tests shown in tutorial I've mentioned refer to built-in methods. How should I write a unit test for a custom class say this is the simplest class I have:
task.h
#ifndef TASK_H
#define TASK_H
#include <QDateTime>
#include <QTime>
class Task
{
private:
bool ifDone;
QString name;
QString description;
QDateTime *startTime;
QTime *start;
QDateTime *endTime;
QTime *end;
bool neededReminder;
QDateTime *reminderTime;
public:
Task(QString _name, QString _description, QDate *dayClicked,
QTime *_startTime, QTime *_endTime, bool reminder);
QString toString();
};
#endif // TASK_H `
task.cpp
#include "task.h"
Task::Task(QString _name, QString _description, QDate *dayClicked,
QTime *_startTime, QTime *_endTime, bool reminder)
{
ifDone = 0;
name = _name;
description = _description;
start = _startTime;
end = _endTime;
startTime = new QDateTime(*dayClicked, *start);
endTime = new QDateTime(*dayClicked, *end);
neededReminder = reminder;
}
QString Task::toString() {
QString task;
task.append(this->name);
task.append(" ");
task.append(this->start->toString("HH:mm"));
task.append(" - ");
task.append(this->end->toString("HH:mm"));
return task;
}
I was trying to #include this class to testing class as well as adding both .h and .cpp files to the project and I didn't manage to do anything. Can anyone write some sample testing methods (for toString method and constructor) for the above class so I could carry on myself with the rest. Thanks in advance.