Unit Testing in Qt with Highly Dependent Functions

允我心安 提交于 2019-12-08 08:56:26

There's a linker trick that you can use. You know which methods and classes your code uses. Get a header files and declarations of those classes and make a small implementation of each that returns values you would like. Then compile those and link in right order. This will then use your own implementation of those methods and you don't need to have the right implementations that require server access.

See for example:

for more details.

PS. Advantage of this linker behaviour is that you don't need to declare your classes as interface first like for example, google mocking framework requires.

You need to use mocking. Google have a C++ mocking framework. You will also need to re-design your code to use interfaces in place of socket code, etc. which are replaced with mock objects when you run your tests.

Take a look at QTestLib. This is the unit testing framework that comes with Qt. Qt allows you to simulate events like mouse click and keyboard events (signals) as well as to snoop on events (signals) generated by your application.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!