0

I'm pretty new in programming. I have a small project that I want to add a unit test to it. I add a new auto test project as new subprojet to my main project but I don't know how should I introduce and include my classes of another source subproject to unit test. I added include sentence of one of my classes but I got some error:

enter image description here

I added

INCLUDEPATH += ../TraceFileSource
include( ../TraceFileSource/TraceFileSource.pro )

to TraceFileTest.pro but it still dosen't work. I review this answer Qt creator: c++: undefined reference to Class::Function but it dosen't clear for me.Is there an easy way to do this?

masoume
  • 33
  • 1
  • 6
  • The error you get is because you forget to *link* with one or more object files or libraries. It has nothing to do with including header files. – Some programmer dude Aug 08 '22 at 07:05
  • And please [don't post images of text](https://meta.stackoverflow.com/questions/285551/why-should-i-not-upload-images-of-code-data-errors-when-asking-a-question). Both code and errors can be copy-pasted as text. – Some programmer dude Aug 08 '22 at 07:05
  • @Someprogrammerdude Thanks for your guide, Whitch library should I add? – masoume Aug 08 '22 at 07:09
  • The test needs to be built with the source or object files that contains the `Communication` member function definitions (implementations). – Some programmer dude Aug 08 '22 at 07:17
  • Yes but I got this error whenever I define an object from Communication class. – masoume Aug 08 '22 at 07:23
  • Yes, but you get the error because you don't build with the file where the `Communication` constructor is defined. In which source file is `Communication::Communication` defined (implemented)? How do you build your test? – Some programmer dude Aug 08 '22 at 07:29
  • @Someprogrammerdude yes I build the test separately – masoume Aug 08 '22 at 07:37
  • You can still build the tests separately, but the test-project or build *must* include all source needed, which includes the ones you want to test. – Some programmer dude Aug 09 '22 at 07:10

0 Answers0