1

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.

Here is the ss from eclipse

  • You include the corrosponding .h files, they contain the interface while the .cpp file contains the implementation. This way the producer of the code can share the code without sharing the implementation. – MrFox Aug 20 '15 at 12:16

2 Answers2

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?

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

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

Community
  • 1
  • 1
Lightness Races in Orbit
  • 378,754
  • 76
  • 643
  • 1,055
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).

zedrian
  • 296
  • 3
  • 10