Visual Studio C ++:单元测试exe项目与谷歌测试? [英] Visual Studio C++: Unit test exe project with google test?

查看:148
本文介绍了Visual Studio C ++:单元测试exe项目与谷歌测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Visual Studio 2010 C ++。我正在试验单元测试,并决定尝试Google测试(gtest)。我有一个现有的项目,编译为MFC可执行文件(我也感兴趣的是如何测试编译到DLL的项目)。我对单元测试约定的理解是,您应该为测试创建一个新的单独项目。所以我在我的单元测试的同一个解决方案中创建了一个新项目。但是如何链接项目?我可以从我的测试项目测试我的exe项目的任意函数/方法吗?

Using Visual Studio 2010 C++. I'm experimenting with unit testing and decided to try Google Test (gtest). I have an existing project which compiles to an MFC executable (I'm also interested in how to test a project that compiles to a DLL). My understanding of the convention for unit testing is that you should create a new separate project for your tests. So I created a new project in the same solution for my unit tests. But how do I link the projects? Can I test arbitrary functions/methods of my exe project from my test project?

这是常规的方法是什么?

What is the conventional way to do this?

推荐答案

将要测试的功能放入静态库,该静态库链接到测试项目和MFC项目,或将文件放在两个项目中。第一个更复杂,但第二个将导致你编译所有的东西两次....

Either put the functionality you want to test into a static library which is linked into both your test project and your MFC project, or put your files in both projects. The first is more complicated, but the second will cause you to compile everything twice....

这篇关于Visual Studio C ++:单元测试exe项目与谷歌测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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