All Projects → benlau → testable

benlau / testable

Licence: Apache-2.0 license
QT/QML Test Runner and Utilities

Programming Languages

C++
36643 projects - #6 most used programming language
QMake
1090 projects
QML
638 projects
shell
77523 projects
javascript
184084 projects - #8 most used programming language

Labels

Projects that are alternatives of or similar to testable

Ssokit Qmake
A Simple & Strong Tool for TCP&UDP Debug
Stars: ✭ 231 (+335.85%)
Mutual labels:  qml
Retiled
An attempt at creating a "desktop" environment mainly for Linux phones and tablets that's similar in function to some parts of Microsoft's Windows Phone 8.x, primarily the Start screen, Search app, navigation bar, Action Center, and the status bar. Development is mainly being done using the PinePhone, so that'll be the main supported device.
Stars: ✭ 41 (-22.64%)
Mutual labels:  qml
clonings
A project for learning Clojure, based on rustlings.
Stars: ✭ 32 (-39.62%)
Mutual labels:  tests
Python Qt5
Unofficial PyQt5 via PyPI for Python 2.7 64-bit on Windows
Stars: ✭ 245 (+362.26%)
Mutual labels:  qml
Manual Testing
This repository contains the General Test Cases for performing Manual Testing on the Web/Mobile application. It also has Test cases related to API Testing. Templates related to Test Plan and BugBash are also updated.
Stars: ✭ 134 (+152.83%)
Mutual labels:  tests
youtube-downloader
youtube-dl GUI simplify
Stars: ✭ 22 (-58.49%)
Mutual labels:  qml
Cool Retro Term
A good looking terminal emulator which mimics the old cathode display...
Stars: ✭ 15,532 (+29205.66%)
Mutual labels:  qml
EntityFrameworkCore.AutoFixture
A library aimed to minimize the boilerplate required to unit-test Entity Framework Core code using AutoFixture and in-memory providers.
Stars: ✭ 31 (-41.51%)
Mutual labels:  tests
go-recipes
🦩 Tools for Go projects
Stars: ✭ 2,490 (+4598.11%)
Mutual labels:  tests
QmlComponentStyle
QML Component Style Demo Based on Qt5.12。QML组件样式Demo,以Qt5.12为基础版本。
Stars: ✭ 55 (+3.77%)
Mutual labels:  qml
mapbox-gl-qml
Unofficial Mapbox GL Native bindings for Qt QML
Stars: ✭ 30 (-43.4%)
Mutual labels:  qml
book-library
📚 A book library app for both Android & IOS ~ Flutter.dev project in Dart
Stars: ✭ 89 (+67.92%)
Mutual labels:  tests
perseus
Perseus is a set of scripts (docker+javascript) to investigate a distributed database's responsiveness when one of its three nodes is isolated from the peers
Stars: ✭ 49 (-7.55%)
Mutual labels:  tests
Qgis Resources
Collection of QGIS resources featured on my blog
Stars: ✭ 237 (+347.17%)
Mutual labels:  qml
KAI
KAI is a distributed computing model written in modern C++ and is cross-plaftorm. Using custom language translators and an executor, KAI provides full reflection, persistence and cross-process communications without having to modify existing source code. KAI Comes with an automated, generational tricolor garbage collector, and Console- and Windo…
Stars: ✭ 13 (-75.47%)
Mutual labels:  tests
Quickvtk
A VTK prototyping application based on QtQuick/QML
Stars: ✭ 228 (+330.19%)
Mutual labels:  qml
qml-webchannel-websockets
QML examples for WebChannel and WebSockets.
Stars: ✭ 26 (-50.94%)
Mutual labels:  qml
QmlFFmpegPlayer
ffmpeg decode, Qml/opengl convert yuv to rgb and render
Stars: ✭ 51 (-3.77%)
Mutual labels:  qml
openjpeg-data
Test files for the OpenJPEG libraries and utilities
Stars: ✭ 37 (-30.19%)
Mutual labels:  tests
qmlvncviewer
VNC viewer component by qt quick
Stars: ✭ 52 (-1.89%)
Mutual labels:  qml

Testable - Qt/QML Unit Test Utilities

Build Status

Testable is an utility library to enhance the function of the two testing frameworks offered by Qt: QTest for C++ and Qt Quick Test for QML.

Features:

  1. Support to run tests from mutiple QObjects
  2. Support to run QTest (C++) and Quick Tests (QML) in a same project
  3. Run specific test case / test object by command line and autotests plugin
  4. Setup custom property and image provider for Qt Quick Test by using engine hook function
  5. Utilities to search QQuickItem from Repeater/Flickable/ListView/GridView

Classes

  1. TestRunner - Multiple test objects runner
  2. Automator - Automator provides an interface to manipulate UI object loaded by QQmlApplicationEngine

Installation

qpm install com.github.benlau.testable

Example

#include <TestRunner>

int main(int argc, char *argv[])
{
    QGuiApplication app(argc,argv);

    TestRunner runner;

    runner.add<DummyTests1>(); // Run tests in DummyTest1 QObject
    runner.add<DummyTests2>(); // Run tests in DummyTest2 QObject
    // Run Qt Quick Test in SRCDIR. It will scan all qml file begin with tst_
    runner.add(QString(SRCDIR));

    runner.addImportPath("qrc:///");
    runner.setEngineHook([](QQmlEngine* engine) {
      engine->rootContext->setContextProperty("MyCustomProperty", new QObject());
    });

    bool error = runner.exec(app.arguments());

    if (!error) {
        qWarning() << "All test cases passed!";
    }

    return error;
}

Exampls are available at examples folder.

Command Line Demonstration

Run all tests with function name equal to "test1"

$ ./testable test1
********* Start testing of DummyTests1 *********
Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.56) (Apple))
PASS   : DummyTests1::initTestCase()
PASS   : DummyTests1::test1()
PASS   : DummyTests1::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of DummyTests1 *********
********* Start testing of DummyTests2 *********
Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.56) (Apple))
PASS   : DummyTests2::initTestCase()
PASS   : DummyTests2::test1()
PASS   : DummyTests2::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of DummyTests2 *********

Run all test functions in DummyTests1 test object

$ ./testable DummyTests1
********* Start testing of DummyTests1 *********
Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.56) (Apple))
PASS   : DummyTests1::initTestCase()
PASS   : DummyTests1::test1()
PASS   : DummyTests1::test2()
PASS   : DummyTests1::cleanupTestCase()
Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of DummyTests1 *********
All test cases passed!

Run a test function via qmltest

./testable QuickTests::test_dummy1
********* Start testing of QuickTests *********
Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.56) (Apple))
PASS   : QuickTests::QuickTests::initTestCase()
PASS   : QuickTests::QuickTests::test_dummy1()
PASS   : QuickTests::QuickTests::cleanupTestCase()
Totals: 3 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of QuickTests *********

Run all tests

./testable

Starting /Users/benlau/src/github/testable/examples/build-testableexample-Desktop_Qt_5_5_0_clang_64bit-Debug/testable...
********* Start testing of DummyTests1 *********
Config: Using QtTest library 5.5.1, Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.56) (Apple))
PASS   : DummyTests1::initTestCase()
PASS   : DummyTests1::test1()
PASS   : DummyTests1::test2()
PASS   : DummyTests1::cleanupTestCase()
Totals: 4 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of DummyTests1 *********
********* Start testing of DummyTests2 *********
Config: Using QtTest library 5.5.1, Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.56) (Apple))
PASS   : DummyTests2::initTestCase()
PASS   : DummyTests2::test1()
FAIL!  : DummyTests2::fail() 'false' returned FALSE. ()
   Loc: [../testableexample/dummytests2.cpp(16)]
PASS   : DummyTests2::cleanupTestCase()
Totals: 3 passed, 1 failed, 0 skipped, 0 blacklisted
********* Finished testing of DummyTests2 *********
********* Start testing of QuickTests *********
Config: Using QtTest library 5.5.1, Qt 5.5.1 (x86_64-little_endian-lp64 shared (dynamic) release build; by Clang 6.0 (clang-600.0.56) (Apple))
PASS   : QuickTests::TestableTests::initTestCase()
PASS   : QuickTests::TestableTests::test_TestRunner()
PASS   : QuickTests::TestableTests::cleanupTestCase()
PASS   : QuickTests::QuickTests::initTestCase()
PASS   : QuickTests::QuickTests::test_dummy1()
PASS   : QuickTests::QuickTests::test_dummy2()
PASS   : QuickTests::QuickTests::cleanupTestCase()
Totals: 7 passed, 0 failed, 0 skipped, 0 blacklisted
********* Finished testing of QuickTests *********

Autotests Plugin

Qt Creator could not detect the tests written by Testable automatically. And therefore it will show nothing in the "Tests" panel and you can't trigger test via Autotests plugin.

To make it work, you have to declare the test object explicitly .

DummyTests1::DummyTests1(QObject *parent) : QObject(parent)
{
    auto ref = [=]() {
        QTest::qExec(this, 0, 0); // Autotest detect available test cases of a QObject by looking for "QTest::qExec" in source code
    };
    Q_UNUSED(ref);
}

The code does actually nothing but it is required for Autotest's parser to recognize the tests.

Autotests does not allow to declare more than a test within a source file. So you have to add this piece of code per source file.

For Qt Quick Tests, you need to declare QUICK_TEST_SOURCE_DIR in pro file:

project.pro file

DEFINES += QUICK_TEST_SOURCE_DIR=\\\"$$PWD\\\"

Then place QUICK_TEST_MAIN in your main.cpp explicitly.

#include <QtQuickTest/quicktest.h>

namespace AutoTestRegister {
    QUICK_TEST_MAIN(QuickTests)
}

int main(int argc, char *argv[]) {

Autotests Screenshot

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].