简体   繁体   English

在Visual Studio中分离和测试C ++类

[英]Separating and testing C++ classes in Visual Studio

I am quite new to both C++ and Visual Studio. 我对C ++和Visual Studio都是新手。 I've got a solution with one project, which is my application. 我有一个项目的解决方案,这就是我的应用程序。 Now I've got to write some C++ classes that form a functional unit. 现在,我必须编写一些构成功能单元的C ++类。 I want to put them separately, probably in their own project (Anything else like “packages” do in Java would be sufficient. Unluckily, I only find myself in Visual Studio with three virtual folders (headers, resources, classes) which even map to the same folder on disk. At least, I would wish to visually separate the classes with headers in the front-end, if the same happens on file system level it would be fine.) and I want to be able to unit-test them from Visual Studio's test running interface. 我想将它们分开放置,可能放在他们自己的项目中(用Java做“包”之类的其他任何事情就足够了。不幸的是,我在Visual Studio中只发现了自己的三个虚拟文件夹(标题,资源,类),它们甚至映射到至少,我希望将前端带有标头的类直观地分开,如果在文件系统级别上发生相同的情况也可以。)并且我希望能够对它们进行单元测试从Visual Studio的测试运行界面。

The MSDN tutorial to set up a unit test assumes a DLL being tested. 用于设置单元测试MSDN教程假定正在测试的DLL。 As per comment, it isn't absolutely necessary to make a DLL for this. 根据评论,并不是绝对需要为此创建一个DLL。 Putting classes in DLLs seems to complicate things by a lot. 放入DLL 似乎使事情复杂化了很多。 I do not need to load the machine code dynamically and I would like to use my classes as easy as if they were in my application project. 我不需要动态地加载机器代码,我想像在应用程序项目中一样轻松地使用类。 Just I want to have it separate somehow and I want write unit-tests for them which should also be separated from both my main program and from the code under test. 我只是想以某种方式将其分开,我想为它们编写单元测试,这些单元测试也应与我的主程序和受测代码分开。 How can I set this up in a simple manner? 如何以简单的方式进行设置?

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

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