How do you run multiple test classes?
I previously asked this in the "newbie" forum but got no responses, perhaps it's not a "newbie" question ;-)...
I've got a directory structure like this:
Code:
/proj
proj.pro
main.cpp
/tests
projtests.pro
main.cpp
/data
data.pri
dataclass.h
dataclass.cpp
/tests
datatests.pri
dataclasstests.h
dataclasstests.cpp
Every dir has a /tests dir beneath it with tests, and main.pro includes data.pri whereas maintests.pro includes datatests.pri.
The only thing is, I can't figure out how to run tests when set up like this?
The tutorial says you have to do this in your test class:
Code:
QTEST_MAIN(<test class name>)
#include "<test class name>.moc"
But as far as I can tell, QTEST_MAIN creates a main function that tests that one class. I'm going to have multiple classes to test, and I want the test main function to live in /proj/tests/main.cpp.
Also the #include "<name>.moc" always shows a warning in QtCreator that the file doesn't exist, although there is no compile-time error.
How do you do this?
Re: How do you run multiple test classes?
Posting the same question twice won't help. I have seen your previous post but to be honest I don't know what you wanted to achieve :) Usually if you want to have multiple tests, you do that through multiple executables or you don't use QTEST_MAIN but provide your own main() where you call QTest::exec() to trigger testing using a given class.
I don't know if it answers your question but in case it does, here you are.
Re: How do you run multiple test classes?
Well, maybe it doesn't matter, since the same person always answers posts ;).
To elaborate on what I'm getting at, I'm used to frameworks(junit, nunit) / IDEs(eclipse, VS) that will run "all" your tests (for a given project) in one go, even if they are in different libraries. I'm trying to do that with QT.
So you're saying I need /proj/tests/projtests.pro to look something like this:
Code:
QT += testlib
TARGET = Tests
CONFIG += console
TEMPLATE = app
SOURCES += main.cpp
include(../data/tests/datatests.pri)
include(../foo/tests/footests.pri)
include(../bar/tests/bartests.pri)
And then a corresponding /proj/tests/main.cpp like this:
Code:
#include <QTest>
int main(int argc, char *argv[])
{
DataTests test1;
FooTests test2;
BarTests test3;
QTest.qExec(&test1);
QTest.qExec(&test2);
QTest.qExec(&test3);
return 0;
}
Do I need to #include the .moc files in this case?
Re: How do you run multiple test classes?
qmake won't "run" anything for you. I'm using a simple script to do that.
Code:
#!/bin/sh
for i in 1 2 3 model
do
cd test$i
./test$i
cd ..
done
test1, test2, test3 and testmodel are my tests.
You need to include "main.moc" only if there is a Q_OBJECT macro in the main.cpp file.