Important: Please read the Qt Code of Conduct -

Unit Testings Q_DECL_HIDDEN classes of a custom Qt Library with Google Test

  • I am using Google unit test framework to test by custom Qt library. I am also using the pimpl pattern to ensure ABI compatibility. Doing this I Q_DECL_HIDDEN some of my classes that are not apart of my API but used in the library. To my understanding this will not export a symbol for those classes.

    Now I have another project that does my unit testing. As part of it's CMake process a link the library so that I can test against it. I also use the install location of the header files. So my question is what happens when I dont export the header or even create a symbol? I shouldnt be able to unit test those classes.

    Here are the two ideas we have so far of how to get around this.

    1. Mark the build with compiler conditionals to export those symbols when building for a unit test.. this would cause us to have to build twice once for unit test.. second for production
    2. just add the header and cpp files to the unit test project manually.. this will work but seems kind of hacky.

    Are they any better practices when dealing with non exported classed and unit testing.

  • Lifetime Qt Champion

    @pjorourke05 If you are implementing unit tests then there is no need to link your library to the test project. Instead include the source code of your lib you want to test in your test project.

Log in to reply