简体   繁体   English

如何在Netbeans中进行C ++单元测试?

[英]How can I do C++ Unit Tests in Netbeans?

I attempted to follow the tutorial here to get Netbeans unit testing setup for C++. 我试图按照此处的教程来获取针对C ++的Netbeans单元测试设置。 It talks about a "Select Elements" portion of the test setup wizard in which one selects the parts of the actual project that are available to the test. 它讨论了测试设置向导的“选择元素”部分,其中选择了实际项目中可用于测试的部分。 This stage in the wizard is absent with the wizard starting on "Name and Location": 从“名称和位置”开始的向导不存在向导的此阶段:

向导截图

When I create a unit test without this part of the wizard, I am unable to include any headers from my project unless I include it in the format #include "../Header.h" and, when I do that, g++ has problems linking the included header to the corresponding implementation. 当我创建没有向导这一部分的单元测试时,除非我以#include "../Header.h"格式包含它,否则无法包含项目中的任何标头,并且当我这样做时,g ++会出现问题将包含的标头链接到相应的实现。

What am I doing incorrectly and what do I need to do to have my unit tests work correctly? 我做错了什么,我该怎么做才能使单元测试正常工作?

NOTE: I am trying to use cppunit, but, the dialog is missing "Select Elements" for all 4 available testing formats (simple C, CUnit, simple C++, CPPUnit). 注意:我正在尝试使用cppunit,但是该对话框缺少所有4种可用测试格式(简单C,CUnit,简单C ++,CPPUnit)的“选择元素”。

The "Select elements" part of the wizard comes up when you activate the wizard by right-clicking the .cpp-file or the .h-file and click "Create Test" . 通过右键单击.cpp文件或.h文件并单击“创建测试”来激活向导时,将出现向导的“选择元素”部分。

If you do "New .. / C/C++ tests/.." this part of the wizard isn't there. 如果您执行“新建../C/C++测试/ ..” ,则向导的这一部分不存在。

I am unable to include any headers from my project unless I include it in the format #include "../Header.h" 除非以#include“ ../Header.h”格式包含标题,否则无法包含项目中的任何标题。

There seems to be an oversight by the template/wizard writers to not address the fact that your tests lies in a directory tests . 模板/向导编写者似乎疏忽了一下,认为您的测试位于目录测试中 You can fix this by adding your project folder as an -I include directory switch. 您可以通过将项目文件夹添加为-I include目录开关来解决此问题。 Use an absolute path. 使用绝对路径。

Linking should not be a problem since the compiler targets the Build directory. 链接应该没有问题,因为编译器的目标是Build目录。 If you do have problems with linking check the properties of the linker options in your CPPUnit test project folder. 如果确实存在链接问题,请检查CPPUnit测试项目文件夹中的链接器选项的属性。

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

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