简体   繁体   English

如何在Xcode 6.1.1中使用谷歌测试运行本地c ++单元测试

[英]How to run local c++ unit tests using google test in Xcode 6.1.1

I am new to google test and xcode. 我是google test和xcode的新手。 Please provide any help. 请提供任何帮助。

I download the google test, and I use xcode to open the googletest.xcodeproj in googletest. 我下载谷歌测试,我使用xcode在googletest中打开googletest.xcodeproj。 I build the project successfully. 我成功地构建了项目。

I want to test against my project. 我想测试我的项目。 I have some unit tests written in myProject/test/unittest.cc The unit tests contain functions that test against myproject/src/some.cc 我有一些用myProject / test / unittest.cc编写的单元测试单元测试包含针对myproject / src / some.cc测试的函数

I did some search, I do not have shell tool as an option in my xcode version. 我做了一些搜索,我的xcode版本中没有shell tool作为选项。 How should I set up the project in xcode? 我应该如何在xcode中设置项目? When I try New project, and import the myProject, it opened a new window with the myProject, but when I try to add the target dependencies, I could not see gtest.framework. 当我尝试New project并导入myProject时,它用myProject打开了一个新窗口,但是当我尝试添加目标依赖项时,我看不到gtest.framework。

May I get information on how to set up the google test for the myProject in xCode please? 我可以获得有关如何在xCode中为myProject设置google测试的信息吗? Thank you. 谢谢。

I am using Xcode version 6.3 (6D570). 我正在使用Xcode版本6.3(6D570)。

I used this guide http://bitrage.de/wp/google-test-with-xcode-6-and-c11/ and it worked fine for me. 我使用了本指南http://bitrage.de/wp/google-test-with-xcode-6-and-c11/ ,它对我来说很好。

I had a couple of issues: 我有几个问题:

  1. I did not get a nice "archive" icon for the compiled gtest.framework as in the guide (step 7). 我没有像编辑指南那样为编译好的gtest.framework获得一个漂亮的“归档”图标(步骤7)。 My icon looked like a blank page. 我的图标看起来像一个空白页面。
  2. I tried to unit test the code declared in a header file but implemented in a cpp file. 我试图对头文件中声明的代码进行单元测试,但是在cpp文件中实现。 To do that I had to: 要做到这一点,我不得不:
    • remove the main() method from the cpp file being unit tested, and 从被单元测试的cpp文件中删除main()方法,并且
    • add the cpp file in question to the "Tests" target (see step 10 in the guide) "Build Phases"->"Compile Sources". 将有问题的cpp文件添加到“Tests”目标(参见指南中的步骤10)“Build Phases” - >“Compile Sources”。

Good luck! 祝好运!

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

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