{"id":22748688,"url":"https://github.com/fgrehm/qmlunit","last_synced_at":"2025-04-14T12:05:59.572Z","repository":{"id":925397,"uuid":"691645","full_name":"fgrehm/qmlunit","owner":"fgrehm","description":"An easy-to-use Unit Testing framework for Qt Declarative UI - QML [unmaintained]","archived":false,"fork":false,"pushed_at":"2010-07-07T15:21:52.000Z","size":488,"stargazers_count":29,"open_issues_count":1,"forks_count":9,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-14T12:05:54.278Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":false,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":"Unmaintained","scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fgrehm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2010-05-28T19:16:52.000Z","updated_at":"2025-01-16T05:56:35.000Z","dependencies_parsed_at":"2022-07-05T21:33:21.155Z","dependency_job_id":null,"html_url":"https://github.com/fgrehm/qmlunit","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgrehm%2Fqmlunit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgrehm%2Fqmlunit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgrehm%2Fqmlunit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fgrehm%2Fqmlunit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fgrehm","download_url":"https://codeload.github.com/fgrehm/qmlunit/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248877985,"owners_count":21176243,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-11T03:34:21.876Z","updated_at":"2025-04-14T12:05:59.538Z","avatar_url":"https://github.com/fgrehm.png","language":"JavaScript","funding_links":[],"categories":["Testing"],"sub_categories":[],"readme":"QmlUnit\n=========\n\nQmlUnit is an easy-to-use Unit Testing framework with asynchronous testing\nsupport for [Qt Declarative UI framework](http://doc.qt.nokia.com/4.7-snapshot/declarativeui.html)\nthat can be used for testing javascript libraries and QML applications.\n\nIt comes with a GUI runner and depends on a modified version of [QUnit](\nhttp://github.com/jquery/qunit) for tests execution.\n\n\nScreenshots\n-----------\n\nhttp://github.com/fgrehm/qmlunit/tree/master/screenshots\n\n\nWriting tests\n-------------\n\nPlease refer to [QUnit API docs](http://docs.jquery.com/QUnit#API_documentation)\nto find out how to write tests in QmlUnit as well.\n\nAltough 100% compatible with QUnit, a QmlUnit test case has a few differences\nfrom plain QUnit tests:\n\n1.  The tests go into a class `*Test.qml` file.\n\n2.  `import QmlUnit 0.1` is required\n\n3.  The test is an instance of `QmlTestCase` or `QUnitTestSuite` element (most\nof the time).\n\n4.  On `QmlTestCase` tests are element methods named test\\_* or asyncTest\\_* (for\n`QUnitTestSuite` check out \"Compatibility with QUnit\" below).\n\n    When writing async tests with QmlTestCase you can write the number of\n    expectations in the method name itself like `asyncTest_2_assync_testing_with_expect_on_definition`.\n\nYou can check out [QmlUnit own tests](http://github.com/fgrehm/qmlunit/tree/master/test/)\nto have an idea of how it works.\n\n### Basic structure\n\nA really simple test might look like this (setup and teardown are commented out to\nindicate that they are completely optional):\n\n    import Qt 4.7\n    import QmlUnit 0.1\n\n    QmlTestCase {\n        //function setup() {\n        //}\n\n        //function teardown() {\n        //}\n\n        function test_fail() {\n            ok(false);\n        }\n    }\n\n### Assertions and asynchronous testing\n\nQmlUnit assertions and methods for dealing with asynchronous testing are the same\nas QUnit's.\n\n#### Assertions\n\n*   _ok( state [, message] )_\n\n\t  A boolean assertion, equivalent to JUnit's assertTrue. Passes if the first\n\t  argument is truthy.\n\n*   _equals( actual, expected [, message] )_\n\n\t  A comparison assertion, equivalent to JUnit's assertEquals.\n\t\n*   _same( actual, expected [, message] )_\n\t\n\t  A deep recursive comparison assertion, working on primitive types, arrays and\n\t  objects.\n\n#### Asynchronous testing\n\n*   _start()_\n\t\n\t  Start running tests again after the testrunner was stopped. See _stop()_.\n\t\n*   _stop( [timeout] )_\n\n    Stop the testrunner to wait to async tests to run. Call _start()_ to\n    continue. You can specify a timeout to fail the test after the given time\n    in milliseconds.\n\n### Interacting with QML elements\n\nAlthough not fully tested, QmlUnit allows you to interact with QML elements pretty\nmuch like you would do in an QML app:\n\n    import Qt 4.7\n    import QmlUnit 0.1\n\n    QmlTestCase {\n        TextInput {\n            id: input\n            validator: IntValidator { }\n        }\n\n        function setup() {\n            // Clean up input for testing\n            input.text = '';\n        }\n\n        function test_text_input_with_invalid_text() {\n            input.text = 'text';\n            ok(!input.acceptableInput, 'invalid text');\n        }\n\n        function test_text_input_with_valid_text() {\n            input.text = '5';\n            ok(input.acceptableInput, 'valid text');\n        }\n    }\n\nWhen testing signals / slots make sure you disconnect signals from elements when\nyou are done testing or use our _connect()_ method which will disconnect them all\nafter a test is run.\n\n#### Helpers\n\nTwo simple helpers are provided to make interaction with QML elements easier:\n\n*   _connect( signal, function )_\n\n    Same as _[Function.connect()](http://doc.trolltech.com/4.3/qtscript.html#using-signals-and-slots)_\n    but it keeps all connected functions in an array for disconnecting after a\n    test is run. Check out [interaction.js](http://github.com/fgrehm/qmlunit/blob/master/scripts/interaction.js#L13)\n    to find out how it works.\n\n*   _click( mouseAreaElement )_\n\n    Shortcut for sending a left button clicked signal to a MouseArea element \n    to avoid writing:\n\n        mouseAreaElement.clicked({\n            button: Qt.LeftButton,\n            buttons: 0,\n            modifiers: Qt.NoModifier\n        });\n\nIf you think we could make use of some other helper just let me know :-)\n\nExample usage:\n\n    import Qt 4.7\n    import QmlUnit 0.1\n\n    QmlTestCase {\n        MouseArea {\n            id: mouseArea\n        }\n\n        function teardown() {\n            input.text = '';\n        }\n\n        function asyncTest_1_clicking_on_mouse_area() {\n            connect(mouseArea.clicked, function (){\n                ok(true, 'MouseArea clicked');\n                start();\n            });\n\n            click(mouseArea);\n        }\n    }\n\n### Compatibility with QUnit\n\nQmlUnit is 100% compatible with QUnit but remember that we don't have a [Document\nObject Model](http://en.wikipedia.org/wiki/Document_Object_Model) available so\nmake sure your code does not depend on it.\n\nQUnit tests should be an instance of QUnitTestSuite and should define a _body()_\nmethod which contains any QUnit test code:\n\n    import Qt 4.7\n    import QmlUnit 0.1\n\n    QUnitTestSuite {\n        function body() {\n            module(\"setup test\", {\n                setup: function() {\n                    ok(true);\n                }\n            });\n\n            test(\"module with setup\", function() {\n                expect(2); // http://docs.jquery.com/QUnit/expect#amount\n                ok(true);\n            });\n        }\n    }\n\n\nRunning tests\n-------------\n\nAs you tipically will have all your tests grouped in some folder, you can run them\nall with `./path/to/qmlunit \u003ctests/folder\u003e`. This will make QmlUnit look for\nall files ending in `Test.qml` in the folder specified.\n\nIf you wanna focus on some specific test case you can supply the desired file to\nQmlUnit executable like `./path/to/qmlunit tests/SomeTest.qml`.\n\nWhen a test is completed, you can click on its name to check out assertions that\nwere run.\n\nDependencies and compilation\n----------------------------\n\nThe framework was compiled and tested against 27/05/2010 [sources](http://qt.gitorious.org/qt)\non Ubuntu 10.04 and depends on:\n\n*   [QUnit](http://docs.jquery.com/QUnit) (distributed with the framework).\n\n    Please note that the version distributed has all HTML related code removed /\n    commented out in order to make it work with QML and is based on [my fork](\n    http://github.com/fgrehm/qunit) which allows for async setup and teardown\n    methods.\n\n*   Qt compiled with declarative ui enabled.\n\n[Henrik Hartz](http://github.com/hhartz) has made QmlUnit compatible with Mac so\nit might work there as well.\n\nBugs and Contributions\n----------------------\n\nIf you find a bug, please [report it](http://github.com/fgrehm/qmlunit) or fork the\nproject, fix the problem and send me a pull request.\n\nThanks goes to [John Resig](http://github.com/jeresig) and other [QUnit contributors](\nhttp://github.com/jquery/qunit/contributors) for their work on QUnit and to [Henrik Hartz](\nhttp://github.com/hhartz) for making QmlUnit compatible with Mac.\n\n\nTODO\n----\n\n* Create a XUnit-like logger\n* Ability to rerun tests\n* Toggle display of errors only\n* Mobile version\n* Provide some way of interacting with C++ code\n* Change mouse cursor for tests names to indicate that it can be clicked\n\n\nLicense\n-------\n\nThis work is licensed under the [MIT license](http://en.wikipedia.org/wiki/MIT_License).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgrehm%2Fqmlunit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffgrehm%2Fqmlunit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffgrehm%2Fqmlunit/lists"}