[Qt-creator] Unit testing private parts of shared libraries

Elvis Stansvik elvstone at gmail.com
Tue Oct 17 19:53:11 CEST 2017


2017-10-17 19:46 GMT+02:00  <timur.kristof at gmail.com>:
>
>> > > > There is another way, and it's used in qbs I believe, that is
>> > > > option 2:
>> > > > #include "Foo.h"
>> > > > #include "Foo.cpp"
>> > > >
>> > > > class FooTest: QObject
>> > > > {
>> > > > ...
>> > > > }
>> > > >
>> > >
>> > > The downside I guess that again, you're not testing the code
>> > > exactly
>> > > as shipped and that compilation times go up a bit.
>> >
>> > What do you mean by "not testing the code exactly as shipped"? When
>> > you include the cpp file (or just compile the same file into your
>> > project), why isn't it the same code as shipped?
>> > Sorry for my ignorance.
>>
>> I was talking about the compiled code. My bad for not being cleared.
>> So what I meant with "as shipped" was "exactly the shared library
>> file
>> that will be part of the product".
>
> Well, you can make sure of that by using the exact same build
> environment and compiler flags for your tests as your library. This way
> it will be the exact same compiled code, won't it?

Yes, being diligent about doing that will of course minimize the risk,
but nothing beats being absolutely sure.

But just to be clear: I'm not saying that this is a necessity or
anything, not at all. I was only bringing that up as one small
downside to re-compiling your source as part of your tests, in the
interest of comparing approaches to letting your tests get at the
non-exported parts of your code.

Elvis

>
> - Timur



More information about the Qt-creator mailing list