开发者

Unit Testing of a protected slot [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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


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:

#define protected public
#include "myclass.h"
#undef protected

This tells the compiler to treat the protected methods as public instead. You can do the same for private functions.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜