qt-test-framework
БесплатноБез исполняемых скриптовНе проверенUse whenever Qt C++ code needs unit or GUI tests in-process: Qt Test entry macros, private-slot test functions, QVERIFY, QCOMPARE and data-driven QFETCH…
от testland★ 18 звёзд на GitHubОб этом скилле
qt-test-framework
Overview
Qt Test is a framework for unit testing Qt-based applications and libraries
(qtover), providing standard unit-testing primitives plus Qt-specific
extensions for GUI event simulation, data-driven tests, and benchmarking. The
QTest namespace carries the verification macros (QVERIFY, QCOMPARE),
data handling (QFETCH, QFETCH_GLOBAL), and entry points (QTEST_MAIN,
QTEST_GUILESS_MAIN, QTEST_APPLESS_MAIN).
Qt Test is in-process - the test executable links the Qt application code
and emits events directly into the QObject event queue. It does not go
through the OS accessibility tree (per desktop-test-strategy-reference), so it
cannot drive a Qt app from a separate process. For out-of-process Qt driving
see winappdriver (Windows via UIA after QAccessible is enabled),
qa-mobile's xcuitest-suite with its references/macos.md (macOS), and the
AT-SPI sections of desktop-test-strategy-reference (Linux).
When to use
- Pure-logic unit testing of
QObject-based classes - view models, data models, signal/slot graphs. - GUI tests of
QWidgetor Qt Quick views where the test executable can link the app code (in-process), avoiding the brittleness of out-of-process accessibility-tree drivers. - Benchmark + performance-regression checks via
QBENCHMARK(qtns). QSignalSpy-based assertions on signal emission order / arguments (qtidx).
Step 1 - Add Qt Test to the build
CMake (Qt 6, the canonical Qt build system per Qt 6 docs):
find_package(Qt6 6.5 REQUIRED COMPONENTS Test Widgets)
qt_add_executable(test_calculator tst_calculator.cpp Calculator.cpp)
target_link_libraries(test_calculator PRIVATE Qt6::Test Qt6::Widgets)
add_test(NAME test_calculator COMMAND test_calculator)
qt_add_executable runs moc automatically, which Qt Test slot discovery
depends on.
Step 2 - Author a test class
The canonical shape per qtover - a QObject subclass with
private slots as test functions:
#include <QtTest/QtTest>
#include "Calculator.h"
class TestCalculator : public QObject {
Q_OBJECT
private slots:
// initTestCase() / cleanupTestCase() run once per class
void initTestCase();
void cleanupTestCase();
// init() / cleanup() run around each test function
void init();
void cleanup();
void addsTwoIntegers();
void emitsResultChangedSignal();
void rejectsDivisionByZero();
};
void TestCalculator::initTestCase() {
qDebug() << "Starting test suite";
}
void TestCalculator::addsTwoIntegers() {
Calculator c;
QCOMPARE(c.add(2, 3), 5); // strict equality assertion
QVERIFY(c.lastError().isEmpty());
}
QTEST_MAIN(TestCalculator) // generates main() + QApplication
#include "tst_calculator.moc" // include moc output
The four lifecycle slots are recognised by name (qtover):
initTestCase (once before any test), cleanupTestCase (once
after), init (per test), cleanup (per test).
Verify: build the target and run ./test_calculator -functions; confirm it
lists your private-slot test functions before authoring data-driven or GUI
cases. If none appear, the slots are not under private slots: or the
#include "tst_*.moc" line is missing - fix and rebuild.
Step 3 - Pick the right entry-point macro
Per qtns, three entry-point macros choose what application class the harness instantiates:
| Macro | Instantiates | Use for |
|---|---|---|
QTEST_MAIN |
QApplication |
Widget GUI tests |
QTEST_GUILESS_MAIN |
QCoreApplication |
Console / non-GUI logic tests |
QTEST_APPLESS_MAIN |
none | Tests of code that itself instantiates its own application object |
Per qtover, if the test class defines a static public
void initMain() method, "it is called by the QTEST_MAIN macros
before the QApplication object is instantiated" - that's the hook
for setting platform-specific environment variables before Qt's
event loop starts.
Step 4 - Data-driven tests
Per qtns, QFETCH retrieves test data values; data is
declared in a sibling _data() slot:
private slots:
void addsTwoIntegers_data();
void addsTwoIntegers();
void TestCalculator::addsTwoIntegers_data() {
QTest::addColumn<int>("a");
QTest::addColumn<int>("b");
QTest::addColumn<int>("expected");
QTest::newRow("zeros") << 0 << 0 << 0;
QTest::newRow("positives") << 2 << 3 << 5;
QTest::newRow("negatives") << -2 << -3 << -5;
QTest::newRow("overflow") << INT_MAX << 1 << INT_MAX + 1; // documents UB
}
void TestCalculator::addsTwoIntegers() {
QFETCH(int, a);
QFETCH(int, b);
QFETCH(int, expected);
Calculator c;
QCOMPARE(c.add(a, b), expected);
}
Per qtover: "A test can be executed multipl
Установить qt-test-framework в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл qt-test-framework?
Use whenever Qt C++ code needs unit or GUI tests in-process: Qt Test entry macros, private-slot test functions, QVERIFY, QCOMPARE and data-driven QFETCH, simulated mouse, key and touch events, QSignalSpy, QBENCHMARK and JUnit XML output for CI, including Qt Quick and QML logic.
Как установить скилл qt-test-framework?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл qt-test-framework запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
skill-creator
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an…
от Anthropicdiscernment-nudge
After you give a substantive answer or draft that the user may act on — advice or recommendations, drafted artifacts such as goals, plans, pitches, proposals…
от Anthropicdata-consolidate
Joins the plant's scheduled exports and connector data into one working dataset — ERP items (NetSuite or Infor M3), sales orders, production work orders…
от Anthropicinspection-to-capa
Runs the quality chain end to end: writes the nonconformance against the requirement it violates, searches history at the moment of writing to say whether…
от Anthropic