How to write tests in C++


i would like to write some tests from my cpp classes. However i cannot find any examples how to do that.
I found some notes related to testlib but could not figure out how to include that. Are there any apps/examples on how to write unit tests for Sailfish OS application classes?

Thanks in advance,

1 Like

Strictly speaking, GTest is a good start if you are looking for something to “just” test :

It’s simple to use and straightforward.
The downside? Included into codebase; but depending how you model your code, you might be able to circumvent that “limitation” (if it feels like that, that is).
Another actually interesting (but less mature) c++ testing fw is
very lightweight, a bit on the easier side, but prone to bugs (output formats are not too many).
Usually code-wise bundled in the same codebase as well (just as gtest is).
If you are a “purist”, these pagan ways might seem like a road to hell to you.


This is clearly a topic that we could improve on - i.e. write some documentation / examples for unit testing.

Little bit of googling found this:


Google test is a really nice framework. Compile time may be huge when using it, though. And since sfos development is mainly qt-centric, you may as well go with Qt Test :

(disclaimer : i never used it for sfos).