File scope test with symbols in 2 .cpp files

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in C/C++test
I have the following:

class IWidget { virtual ~IWidget(); };

#include "IWidget.h"
IWidget::~IWidget {}

#include "IWidget.h"
class Widget : public IWidget { virtual ~Widget(); };

#include "Widget.h"
Widget::~Widget() {}

When I try to write a test for the Widget class, I get errors due to the ~IWidget symbol not being defined. I can stub it out to fix this, but I don't want to stub it (this would cause code duplication in our real-world case, plus should I really have to stub out an interface?). Is there a way to do "file scope" unit testing where the run can get symbols from two different CPP files?


  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Hello PatrickVHines,

    You are able to scan multiple individual files by holding down the control button ("ctrl") and clicking on the files you wish to scan in the GUI, including these multiple files into the scope. In this case, it would be both Widget.cpp (which calls Widget.h) and IWidget.cpp (which calls IWidget.h). In this way, you can include multiple necessary files into a file-scope level Test Configuration scan.

    To achieve the same on the command line, use the "-resource" option, once for each particular resource (in this case, file) you wish to have scanned. Example: "-resource jvann/workspace/Widget.cpp -resource jvann/workspace/IWidget.cpp". Please do note that the "-resource" option is not file-centric; it can be used to reference broader-scale resources, such as entire projects, as well.


    -Jamie Vann
    Associate, Customer Support
Sign In or Register to comment.