Can I use CppUTest in Qt Creator?

416 views
Skip to first unread message

Loki Lawliet

unread,
Dec 13, 2014, 7:32:08 PM12/13/14
to cppu...@googlegroups.com
If so, do I need to modified the default qmake command or I need to add something in my .pro file?

For now, I create several cpputest test cases for my Qt project in Qt Creator on Linux(Ubuntu). I imported cpputest as an external library into my current Qt project and it reports no error only if I create a normal AllTest.cpp file in my project, which reports a multiple main errors.

I am new to compile C++ project with multiple frameworks and libraries. I get quite confused on this part. I understood unit test cases make multiple main entrance for such a C++ project. But I don't know how to configure it so it will compile "separated", one for my application and one for unit test entrance.

Any hint would help. An example Qt .pro file with cpputest set up or an example qmake command will help a lot. Thank you.

James Grenning

unread,
Dec 14, 2014, 9:23:22 AM12/14/14
to cppu...@googlegroups.com
As you see from the errors, you cannot have two main()s. You will need
two builds or at least two different build targets. One for your
regular QT app, and one to build a test runner. I suppose you could add
some menu item to run tests, capture the text and put it on a QT window
(or something like that). I have not used QT, so I am just suggesting
things for you to look at.

Is there a way with QT to create a console or command line app? Can you
write a help world app with QT? Find that example and add RUN_ALL_TESTS
to the hello worlds app.

// QT hello world
#inclde "QTheaders needed"
#include "CppUTest/CommandLineTestRunner.h"

int main(int ac, char** av)
{
// do the qt minimal program
return RUN_ALL_TESTS(ac, av);
}

See if you make progress there. Once you have that, start folding in
some of your code to that build.

James

--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C -
pragprog.com/titles/jgade/
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)
> --
> You received this message because you are subscribed to the Google
> Groups "cpputest" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to cpputest+u...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

James Grenning

unread,
Dec 14, 2014, 9:25:56 AM12/14/14
to cppu...@googlegroups.com
In my previous email, s/help world/hello world/

Loki Lawliet

unread,
Dec 14, 2014, 12:26:55 PM12/14/14
to cppu...@googlegroups.com
Thank you, James. I realized that I need two different build for doing so.

Yesterday I tried to solve this problem by manually "make test" in terminal from a different Makefile. Your idea is better. So I can also do test in Qt IDE instead of open a new terminal window.

James Grenning

unread,
Dec 14, 2014, 1:23:24 PM12/14/14
to cppu...@googlegroups.com
Which idea is better?

Having separate makefiles seems like a fine idea to me. You also want
the option to do a command line build and test so that you can have a
automated CI build.

--------------------------------------------------------------------------
James Grenning - Author of TDD for Embedded C -
pragprog.com/titles/jgade/
wingman-sw.com
wingman-sw.com/blog
twitter.com/jwgrenning
facebook.com/wingman.sw
[![wingman
software](http://www.wingman-sw.com/images/wingman.png)](http://wingman-sw.com)
>>>> send an email to cpputest+u...@googlegroups.com <javascript:>.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "cpputest" group.
>>> To unsubscribe from this group and stop receiving emails from it,
>>> send
>>> an email to cpputest+u...@googlegroups.com <javascript:>.
Reply all
Reply to author
Forward
0 new messages