Author Topic: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++  (Read 7222 times)

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« on: September 14, 2010, 01:06:49 am »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #1 on: September 14, 2010, 09:20:49 am »
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...
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #2 on: September 14, 2010, 01:02:02 pm »
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.

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #3 on: September 14, 2010, 03:22:21 pm »
Code
    #include "UnitTest++.h"
 
    int main()
    {
        return UnitTest::RunAllTests();
    }

What happens if you put the RunAllTests() somewhere in a method of your GUI code ?

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #4 on: September 14, 2010, 03:25:48 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #5 on: September 14, 2010, 04:40:31 pm »
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++
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #6 on: September 14, 2010, 05:37:47 pm »
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.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #7 on: September 14, 2010, 05:54:41 pm »
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 :)
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline killerbot

  • Administrator
  • Lives here!
  • *****
  • Posts: 5490
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #8 on: September 14, 2010, 08:48:09 pm »
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.

Offline Otto

  • Multiple posting newcomer
  • *
  • Posts: 21
Re: Help - unit testing with Code::Blocks, WxWidgets and UnitTest++
« Reply #9 on: September 15, 2010, 02:04:22 am »
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.