DESCRIPTION Qt-Mocks is a unit testing framework inspired by Google Test, but designed for use with the Qt unit testing framework. Its three priorities are:
- Simple to use, e.g. reading the code should be clear in its purpose.
- Efficient in speed.
- Ensure type safety of tests.
The order of priorities are listed in the order of importance.
Sites:
BUILD ENVIRONMENT
Qt-Mocks is mainly developed on Mageia and Fedora using just the standard development libraries, KDE, and QT. It is also tested on Debian, Fedora, and Microsoft Windows.
DIRECTORY MAP
All the source code is listed in the src directory. Installation instructions can be found in the INSTALL file. For a listing of all the contributors to Qt-Mocks you can find that information in the CREDITS file. All the current news can be be found on the main website.
INSTRUCTIONS
Once compiled you can link it into your projects and do some of the examples below.
Create unit tests that are more descriptive:
struct Test : QObject
{
Q_OBJECT
qint32 add2(qint32 val)
{
val += 2;
return val;
}
private slots:
void test()
{
const qint32 value{2};
const auto actual{add2(value)};
const auto expected{4};
QVERIFY_THAT(actual,
equals(expected));
}
};
common_matchers::EqualMatcher< ValueType > equals(const ValueType &expected)
Creates a matcher that will expect that a value is equal to the matcher's expected value.
Create unit tests that mock function behaviour:
struct Adder
{
virtual ~Adder();
virtual qint32 add2(qint32 val) const = 0;
};
struct AdderMock : Adder
{
QMOCK(qint32, add2, (qint32), (const));
};
struct Test : QObject
{
Q_OBJECT
private slots:
void test()
{
AdderMock mock{};
Expectations expected{mock};
const qint32 value{2};
QVERIFY_CALL(expected, add2, (qint32), (const))
.require();
const auto actual{mock.add2(value)};
const auto expected{4};
QVERIFY_THAT(actual,
equals(expected));
}
};
ValueGiver< ReturnType > give(ReturnType value) noexcept