PDA

View Full Version : QtTest - Am I missing the point



hubbobubbo
21st December 2009, 18:32
Hi

I was just looking at QtTest for unit testing but I must be missing something. Since each test will define its own main with the QTEST_MAIN(TestXXX) function. How do I set up the testing with many testcases, I can only have 1 main function?

Is it supposed to be used in another way. Preferably I would like to have the unittest even in the same project as my application, is there a way to compile the tests individually. How are you doing this.

Thanks

wysota
22nd December 2009, 07:54
Each private slot of your test class is a test function. Each test function can cover many test cases through data-driven testing.

Cesar
30th January 2010, 14:37
How do I set up the testing with many testcases, I can only have 1 main function?
I'm also concerned about this problem. There seem to be no way to organize tests in hierarchy. Take xUnit testing framework family's approach as an example: there are test cases which can be organized in test suites, which in turn can be included into other test suites. All this stuff makes it possible to organize tests in a nice tree which mimics the project's structure and simplifies both navigation between code and corresponding tests. Also this tree has one entry point thus eliminating the need to find the right one.

On the other hand there's QtTest framework. Personally I took tests for Qt Creator as a reference. Immediately two questions arose:

How can I run all its tests in one go?
How can I find a test that covers a particular piece of code?


Each test function can cover many test cases through data-driven testing.
That's a nice feature indeed, but it has quite a different goal. If I got it right it is similar to jUnit's and PhpUnit's data providers. They just feed the test with different sets of data to see how the same piece of code can handle it. So it cannot be used to test different parts of system, while hubbobubbo and I look for a way to organize tests for different pieces of code.

Sorry for such an offensive manner, I'm really eager to utilize QtTest, but it's so irritating to miss features you've got used to while others tend to say "you don't need them". Maybe there's another way to achieve the same goals with QtTest but neither hubbobubbo nor me just couldn't manage to find them? Please share your experience so that we also can be happy :D

wysota
30th January 2010, 15:18
Each test case is a separate private slot. You can have as many of them as you want and each of them can be executed with different input data. In result you get an executable testing a single unit of code (that's why it's called unit testing, isn't it?). You can group executables in hierarchies using directories according to a desired structure you wish to obtain. To execute all tests in one go simply have a script that will do it for you. The easiest way to do it on Unix is to issue:
find . -type f -perm +111 -exec "{}" \;
which will execute all executable files from all subdirectories of the current directory.