Search code examples
c++unit-testinggoogletest

Are Unit Tests with Google Test exported with project?


I've been studying Unit Testing with Google Test in C++.

If the purpose of Unit Testing is to ensure certain segments or objects of the code are working the way they are supposed to, I would assume it's not necessary to compile and export the unit testing code with the final project, right? It's not like the user will be using it anyway. It just seems like it makes the project size unnecessarily larger.

My main question is: will all the Unit Testing code be compiled and exported with the final project or will I have to manually delete all the Unit Tests before exporting it?

Is there a best (or common) practice for Unit Testing and exporting projects?


Solution

  • If you're publishing a library, it's quite common to publish the unit tests. Imagine you're developing on Mac or Linux, for example, and someone wants to compile on Windows. Well, they should probably be able to run your tests to ensure they pass on a different environment. Or Android, or some microcontroller. Whatever.

    Also, someone might decide to help you improve your project. They'll add a nifty-cool feature. It's nice if they can run your unit tests to make sure they don't break anything.

    So yes, if you're publishing your project as source code, include the unit tests. If you're only publishing a compiled library, you can exclude them.