受保护插槽的单元测试
您好,我尝试对受保护的插槽实施单元测试 在测试函数中,我创建了一个类的对象,并使用该对象调用该类的受保护对象 但它给了我一个错误,如下所示:
/home/puneet/puneet/office/alkimia/ payment/backend/backend.h: In member function 'void BackendTest::test_initialization()': /home/puneet/puneet/office/alkimia/ payment/backend/backend.h:70: 错误: 'void Backend::initializeUsers(const QStringList&)' 受到保护
Hello I tried to implement unit testing for a protected slot
In the testing function I made an object of a class and called a protected of that class using that object
But it gave me an error as follows:
/home/puneet/puneet/office/alkimia/payment/backend/backend.h: In member function ‘void BackendTest::test_initialization()’:
/home/puneet/puneet/office/alkimia/payment/backend/backend.h:70: error: ‘void Backend::initializeUsers(const QStringList&)’ is protected
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通常处理这个测试的方法是使用以下定义:
如果您正在测试的类的头文件是“myclass.h”,您在测试文件中#include它,则执行:
这告诉编译器处理将受保护的方法改为公共方法。您可以对私有函数执行相同的操作。
The way I usually handle this for tests is to use the following defines:
If the header file for the class you are testing is "myclass.h", where you #include it in the test file, do:
This tells the compiler to treat the protected methods as public instead. You can do the same for private functions.