如何将C ++单元测试添加到现有项目? [英] How to add C++ unit tests to an existing project?

查看:179
本文介绍了如何将C ++单元测试添加到现有项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有Visual Studio 2015社区。我有一个C ++项目,我通过选择Visual C ++>创建。一般>新项目窗口中的空项目。

I have Visual Studio 2015 Community. I have a C++ project that I created by selecting Visual C++ > General > Empty Project in the New Project window.

我正在阅读"使用测试资源管理器对现有C ++应用程序进行单元测试"。

I am reading "Unit testing existing C++ applications with Test Explorer".

此页面说明如何将单元测试添加到现有的Visual Studio 2015 C ++项目中。我的项目被编译为.exe文件,所以我指的是"将测试链接到对象或库文件"。在页面中标题。

This page explains how to add unit tests to an existing Visual Studio 2015 C++ project. My project is compiled as an .exe file, so I am referring to "To link the tests to the object or library files" heading in the page.

它说:"在文件菜单上,选择新建,项目,Visual C ++,测试,C ++单元测试项目。"但我没有这样的选择(我只有"托管测试项目"和"本机单元测试项目")。

It says: "On the File menu, choose New, Project, Visual C++,Test, C++ Unit Test Project.", but I do not have such a choice (I only have "Managed Test Project" and "Native Unit Test Project").

此外,当页面显示"添加的名称时"。 obj
.lib
文件。"我应该输入我要在"ProjectToTest / Debug"中测试的项目的每个.obj文件的名称。 ?语法是什么?

Also, when the page reads "add the names of the .obj or .lib files.", am I supposed to enter the names of every .obj file of the project I want to test in "ProjectToTest/Debug"? What is the syntax?

最后,它还告诉我"添加待测项目的头文件目录",什么是头文件目录?包含所有.h文件的目录?如果项目对标题和代码文件使用相同的目录怎么办?

Lastly, it also tells me to "add the header directory of the project under test.", what is the header directory? The directory containing all the .h files? What if the project is using the same directory for header and code files?




谢谢

Thanks

推荐答案

嗨路易斯,

这是您正在阅读的页面吗?

https://msdn.microsoft.com/en-us/library/hh419385.aspx

 

>>它说:"在文件菜单上,选择新建,项目,Visual C ++,测试,C ++单元测试项目。"但我没有这样的选择(我只有"管理
测试项目")。和"本机单元测试项目"。

应该是这样的。如果是由Native C ++编写的,您将根据项目选择单元测试项目。

 

 

>>此外,当页面显示"添加.obj的名称或  
。lib files。",我应该输入我要测试的项目的每个.obj文件的名称在"ProjectToTest / Debug"中?语法是什么?

  ;

你只做" < span style ="font-size:medium">如果
下的代码test不会导出您要测试的函数 ",然后是,您需要添加.obj或。的每个名称。 lib你想要
来测试。

 

>>最后,它还告诉我要"添加正在测试的项目的头文件目录",什么是头目录?包含所有.h文件的目录?如果
项目对标题和代码文件使用相同的目录怎么办?

只有在同一项目中添加单元测试
才会发生这种情况 ,所以它只是回答你的问题。

 

 

 

如果被误解,请随时告诉我。

 

 

希望它有所帮助。

祝你好运,

Fletch


这篇关于如何将C ++单元测试添加到现有项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆