Hi, I'm new to C++ and C::B.
I followed this tutorial on how to set C::B and UnitTest++: http://wiki.codeblocks.org/index.php?title=UnitTesting
It worked great. Now I want to build a wxWidgets project and use unit tests there. But, in that tutorial, the main() function was used to invoke the tests. I mean, the project was exclusively to test the Leap Year.
This time the wxWidgets project has the OnInit() method, but that instantiates the Frame and the rest of the application.
I'm confused: how do I fit the call to my unit tests here? Do I need a new target? If so, how to create one?
Thanks in advance.
If you want to debug the UI, take a look at wxTest ( http://wxtest.sourceforge.net/ ), I think the wx guys are using it themselves...
No, I was talking about the actual code. My question is how to call the unit tests in a wx project.
But thanks for the link. Can be useful later.
#include "UnitTest++.h"
int main()
{
return UnitTest::RunAllTests();
}
What happens if you put the RunAllTests() somewhere in a method of your GUI code ?
But somewhere, where?
I could put on the OnInit(), but that doesn't make a lot of sense, because it will run the tests, then open the GUI. I should have a way to run the tests only.
you've got tons of possibilities :)
1. could create another application
2. could add command line argument (-test) that does it
3. something else
Most people settle on option 1. and it is explained in the tutorial about unittest++
Option 2 seems a bit odd to me. Command line argument during development using an IDE?
About option 1, I would have a project for unittest++, another for my unit tests and a third one for the project itself? Not exactly as the tutorial.
The idea is to add a post build step that executes the unittest project.
The unittest project reports errors similar to your to the errors produced by the compiler, this way you can click them in the IDE
and it will go to the line with the failing test.
The tutorial is missing the real project :)
note also, that typically a bunch of functionality is implemented in a library. Then the setup would even be little more different.
1) project that builds *my* library
2) test project (console app) that contains the tests, these will include the exported headers from the library, and will link with the library binary
the tutorial is a simplification, in that way that the test code and the tested code all belong to the same (console app) project.
So the library is the wx project (both GUI and core classes) and a second project with the unit tests.
I'll try and see what I can do.
Thanks.