Qt: Automated GUI testing

Created on 21 Feb 2017  路  12Comments  路  Source: therecipe/qt

When you doing testing of any GUI system it if usually either impossible or very difficult.

Like how people use selenium for web app testing.

I am curious if there is support in Qt to do this type of testing ?

All 12 comments

QT do have it's own framework for testing:

http://doc.qt.io/qt-5/qtest-overview.html

the binding are already there:

https://github.com/therecipe/qt/tree/master/testlib

but I personally don't have any experience with it.

http://doc.qt.io/qt-5/qttestlib-tutorial3-example.html

Looks like there is some support natively with QT.

Is it possible we that one or two of the examples could have this done, so I can see how it's done with golang ?

If this is something people find useful I would be happy to help build some tooling to make it as streamlined as possible.

I started to to do the same with i18n to automate language aspects between golang and qml but got sidetracked. Will share something when I get a basic thing going.

@bclermont thanks.

I will close this for now, as its there and is a matter of trying it out

@joeblew99

I just looked into the examples and it seems like the QTest is currently not available.
But I'm working on that.
The other thing is, that the examples make use of these macros: http://doc.qt.io/qt-5/qtest.html#macros and I'm not sure, if there is a way to support these at all. (But maybe they are not that important anyway)

@therecipe

Thanks for trying to get this going.
Guess its a matter of you trying out getting a very basic example going.

Then we can dogfood it from there.

@therecipe can you give us an example how to use testlib please?
I can imagine tests would run slower than how we do without cgo, so if you have a special workflow would be appreciated.

Thank you.

@arsham I added some new examples here: https://github.com/therecipe/advanced-examples/tree/master/test

Yeah, the tests are a bit slower but most time is still spend compiling the code.

I also haven't had time to add the missing functions from QTest, but you can pretty much automate everything with http://doc.qt.io/qt-5/qtesteventlist.html or by directly calling the signals/functions that you want to test.

edit: just run "qtmoc" (+ "qtrcc" for the qml example) and then "go test -v" as usual

Thanks, you're my hero!
This is great. Is there a way to change the behaviour of qtmoc in such a way that the moc parts of tests would be in their own (optional) files (_test.go) and package (_test)?
I understand all types are exported, therefore there shouldn't be any issues on accessing them during tests.

No problem :)
I looked into this, but it unfortunately seems like you can't use cgo from within files that have the suffix _test.go https://github.com/golang/go/issues/4030 and https://github.com/golang/go/issues/18647
And you also can't implement methods for a structs from a different package. (So moving the implementation into a *_test package won't work.)

So I'm sorry, but you will need to create the *_test packages yourself and then import them from your test files manually.

All good, I am actually pleased with the current situation. BTW I've made a new wiki page, please have a look and edit if required.

Cheers mate.

Will do, but it's already a little late here. Will check it out tomorrow though.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

quantonganh picture quantonganh  路  6Comments

angiglesias picture angiglesias  路  5Comments

ismlsmile picture ismlsmile  路  5Comments

xlucas picture xlucas  路  7Comments

amlwwalker picture amlwwalker  路  3Comments