简体   繁体   English

Qt C ++集成测试(网络摄像头,数据库)

[英]Qt C++ Integration tests (webcam, db)

I am developing an app in Qt, which uses webcam and then saves some summary data into the database. 我正在Qt中开发一个应用程序,该应用程序使用网络摄像头,然后将一些摘要数据保存到数据库中。 I am using Qt except 3rd party library which is used to capture images from webcam and generate needed data. 我正在使用Qt,除了第三方库(用于从网络摄像头捕获图像并生成所需数据)之外。

Question is how can I implement integration tests with QTest? 问题是如何使用QTest实施集成测试?

I mean basically, to be sure, that everything works I need to: 基本上,我的意思是确保一切正常,我需要:

  1. Simulate webcam somehow (pass some video or list of images) so that I can test whether gathered data is correct 以某种方式模拟网络摄像头(传递一些视频或图像列表),以便我可以测试收集的数据是否正确
  2. Simulate db or create some mock to the Qt db access classes so that I can verify that proper rows are inserted or maybe use some memory db for the test? 模拟数据库或对Qt数据库访问类创建模拟,以便我可以验证是否插入了正确的行,或者可以使用一些内存数据库进行测试?
  3. Change system clock to simulate timer events - some of the actions in the app are performed after specific amount of time elapsed - how can I simulate that in the tests? 更改系统时钟以模拟计时器事件-应用程序中的某些操作在经过特定时间后执行-如何在测试中模拟?

So answering my own question: I should use some mocking library like google mock. 所以回答我自己的问题:我应该使用一些模拟库,例如google模拟。 This way I can mock my class for gathering images from camera and call callbacks with captured images. 这样,我可以模拟我的类以从相机收集图像,并使用捕获的图像调用回调。 I can do the same thing for db access and just verify, that proper inserts were generated. 对于数据库访问,我可以做同样的事情,只是验证是否已生成正确的插入。

Then it comes another question - how can I provide mocks to my application instead of real classes when executing a test? 接下来是另一个问题-执行测试时,如何为我的应用程序提供模拟,而不是实际类? Should I make an interface for them and then provide as constructor arguments to the QWindow? 我应该为它们创建一个接口,然后将其作为构造函数参数提供给QWindow吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM