How to write tests in C++

Hi,

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,
Cheers,
Andreas

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 https://github.com/catchorg/Catch2
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.

2 Likes

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: https://sudonull.com/post/72744-Development-for-Sailfish-OS-Unit-Testing-Qt-C-for-Sailfish-OS

3 Likes

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 :

https://doc.qt.io/qt-5/qtest-tutorial.html

(disclaimer : i never used it for sfos).

3 Likes