comparing QTest with other frameworks
Asked Answered
C

3

7

Can you compare popular unit test frameworks for C++ with QTest of Qt?

(cppunit, boost test, google test etc..)

What are the advantages disadvantages? Thank you.

note: GUI test is not very important for us.

Cappella answered 2/2, 2011 at 20:43 Comment(0)
B
5

QTest is the only framework I know of for unit testing UI components. We've used it with some success but stick to Boost.Test for our regular unit testing.

Buttons answered 2/2, 2011 at 21:19 Comment(0)
G
3

Based on my experiences I cannot recommend Qt test framework. The two possible advantages, what can be mentioned are:

  • QSignalSpy: to verify emitted signals (only useful for Qt), but this can be used also with other testing framework
  • easy to write parametrized tests

The main disadvantages:

  • Fixtures are not supported by default, you have to workaround it in setUp tearDown
  • QCOMPARE cannot compare values with different type. For example comparing two std::chrono::duration with different ratio is impossible, although they are equally comparable. It is very annoying to cast just for QCOMPARE

Boost is simple and usable, it works well for most cases, without suprises.

The main advantage of Google test framework is the mocking support. But this feature can be used for other frameworks, as well. It has a lot of great features, like defining expected call sequences, custom matchers, assertions can be human readable. But it takes time to be familiar with these features (assuming that you need them).

I want to mention one more framework: Catch. It is a header-only framework, with very few assertions. Eg. REQUIRE(a == b) will work and values of a and b will be resolved on failure. There are no need for fixture classes or boilerplates, you can just define sections in a test case, it will be performed N-times, with different sections. It is very straightforward, human readable. At the other side, it takes time to be compiled by default.

Ghassan answered 11/9, 2017 at 7:25 Comment(0)
B
1

QtTest (up to Qt 5.7) does not provide the ability to expect an assert in the uut, while Googletest does have the concept of death-tests and can have a test that tests for an assert. We find this useful in Googletest and anoying that it is missing from QtTest!

Bab answered 11/8, 2016 at 7:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.