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

Elvis Stansvik elvstone at gmail.com
Tue Oct 17 20:05:27 CEST 2017


2017-10-17 19:57 GMT+02:00  <timur.kristof at gmail.com>:
> On Tue, 2017-10-17 at 19:53 +0200, Elvis Stansvik wrote:
>> > > > 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.
>
> I didn't mean to offend, only asked because I was curious about your
> thoughts. :)

Not offended :) Just wanted to make sure I wasn't coming off as
preaching something.

>
> One more thing:
> While I see why it is desireable to test the code exactly as shipped,
> but there are also benefits to testing with different settings. For
> instance, in one project I used the approach where I simply compiled my
> library code into the tests. Then I ran the tests with various
> optimization flags and they each helped me discover different kinds of
> errors in the code.
>
> So it might be worth to test with multiple build settings as well.

Absolutely, and thanks for bringing up that point.

Elvis

>
> Cheers,
> Timur



More information about the Qt-creator mailing list