I have a Qt Unit test (sub)project, which generates me one class (with the main generated by QTEST_APPLESS_MAIN
).I can start this from within Qt Creator as cons
Based in the accepted answer and if you are using C++11 you could be interested in a solution using lambdas. It avoids you write the same code everytime. Although you can replace the lambda with a function, I think a lambda is cleaner.
#include
#include "test1.h"
#include "test2.h"
int main(int argc, char** argv)
{
int status = 0;
auto ASSERT_TEST = [&status, argc, argv](QObject* obj) {
status |= QTest::qExec(obj, argc, argv);
delete obj;
};
ASSERT_TEST(new Test1());
ASSERT_TEST(new Test2());
return status;
}
#ifndef TEST1_H
#define TEST1_H
Sample test
#include
class Test1 : public QObject
{
Q_OBJECT
private Q_SLOTS:
void testCase1();
};