如何包含* ?我的c++项目中的cpp文件?

时间:2022-02-17 21:09:53

I have to write UnitTest with CppUnit library but i need little help. I'm including mainfunction in my test class but it doesnt works.

我必须用CppUnit库编写UnitTest,但是我不需要什么帮助。我把mainfunction包括在我的测试类中,但它不起作用。

如何包含* ?我的c++项目中的cpp文件?

2 个解决方案

#1


4  

I haven't worked with CppUnit so it's possible this is conventional but, in general, you never #include .cpp files. Are you sure you're doing this right?

我没有使用CppUnit,所以这可能是常规的,但是一般来说,您永远不会包含.cpp文件。你确定你做得对吗?

If you are, you need #include "mainfunction.cpp", because #include <> does not look in the current directory, only library include paths.

如果你是,你需要#include "mainfunction。因为#include <>不在当前目录中查找,所以只有库包含路径。

You got this right for the .h, so I don't understand why you changed it for the .cpp.

你得到了这个。h,所以我不明白你为什么要把它换成。cpp。

#2


1  

Unit tests normally work as a separate project. For example, when you develop prject "MyMath", you should create another project "MyMathTest" and put all .cpp files that contain your tests into that (but not into your main project).

单元测试通常作为一个单独的项目工作。例如,当您开发prject“MyMath”时,您应该创建另一个项目“MyMathTest”,并将包含您的测试的所有.cpp文件放在其中(而不是主项目中)。

#1


4  

I haven't worked with CppUnit so it's possible this is conventional but, in general, you never #include .cpp files. Are you sure you're doing this right?

我没有使用CppUnit,所以这可能是常规的,但是一般来说,您永远不会包含.cpp文件。你确定你做得对吗?

If you are, you need #include "mainfunction.cpp", because #include <> does not look in the current directory, only library include paths.

如果你是,你需要#include "mainfunction。因为#include <>不在当前目录中查找,所以只有库包含路径。

You got this right for the .h, so I don't understand why you changed it for the .cpp.

你得到了这个。h,所以我不明白你为什么要把它换成。cpp。

#2


1  

Unit tests normally work as a separate project. For example, when you develop prject "MyMath", you should create another project "MyMathTest" and put all .cpp files that contain your tests into that (but not into your main project).

单元测试通常作为一个单独的项目工作。例如,当您开发prject“MyMath”时,您应该创建另一个项目“MyMathTest”,并将包含您的测试的所有.cpp文件放在其中(而不是主项目中)。