Qt test No such file or directory when the tested class needs other classes (recursively)
-
Hello,
I am trying to implement unit testing on a project.
So my project has two subdirs, one with software's functionalities code and another one dedicated for unit tests.
I create a file for each class I want to test, if this class does not need any other class, I'm able test it. But if the class I'm testing needs another class, this error occurs saying that the class needed by the tested class is missing (this is recursive, if the class missing needs another class it will also be missing):
Structure/layer.h: No such file or directory
Detailed example :
Material class, we can see that it does not require other classes (other than Qt/C++ classes). Here i don't get any errors.#ifndef MATERIAL_H #define MATERIAL_H #include <iostream> #include <QObject> #include <QtCore/qmath.h> #include <math.h>
Structure class, it is the opposite, and I get multiple errors
#ifndef STRUCTURE_H #define STRUCTURE_H #include <QObject> #include <QLibrary> #include <iostream> #include <array> #include <Structure/layer.h> #include <BaseDeDonnees/materialdb.h>
Here is the *.pro of my unitTest project.
I tried to add layer.h without successQT += testlib QT += gui CONFIG += qt testcase TEMPLATE = app SOURCES += \ main.cpp \ test_material.cpp \ test_structure.cpp \ ../cpp/Structure/material.cpp \ ../cpp/Structure/structure.cpp \ ../cpp/Structure/layer.cpp \ # test_session.cpp \ # test_charge.cpp \ # ../cpp/SessionProjet/session.cpp \ # ../cpp/Charges/charge.cpp \ HEADERS += \ test_material.h \ test_structure.h \ ../cpp/Structure/material.h \ ../cpp/Structure/structure.h \ ../cpp/Structure/layer.h \ # test_session.h \ # test_charge.h \ # ../cpp/SessionProjet/session.h \ # ../cpp/Charges/charge.h \ INCLUDEPATH += \ $$PWD \
-
@Grpt Please avoid using screenshot, it is a pain for other to reply. It is better when you copy/past text.
Now to your issue: you cannot insert comments between line breaks.
Remove those lines or move them to the end of theSOURCES
andHEADERS
definition. -
@KroMignon Thanks for your answer, I've edited my topic.
I tried to execute without the unnecessary lines but it was still not working.I tried to add "../cpp/" to INCLUDEPATH then clean, execute qmake and recompile
INCLUDEPATH += \ $$PWD \ ../cpp/ \
Now the files are found but i get a new error "No rule to make target '../cpp/Structure/materialdb.cpp', needed by 'debug/materialdb.o'. Stop."
I've searched on google but I can't find a solution that works for me
I am using Qt 5.13.2 MinGW 64-bitHere is the edited *.pro
QT += testlib QT += gui CONFIG += qt testcase TEMPLATE = app SOURCES += \ main.cpp \ test_material.cpp \ test_structure.cpp \ ../cpp/Structure/material.cpp \ ../cpp/Structure/structure.cpp \ ../cpp/Structure/layer.cpp \ ../cpp/Structure/materialdb.cpp \ ../cpp/Structure/avstdroad.cpp HEADERS += \ test_material.h \ test_structure.h \ ../cpp/Structure/material.h \ ../cpp/Structure/structure.h \ ../cpp/Structure/layer.h \ ../cpp/Structure/materialdb.h \ ../cpp/Structure/avstdroad.h INCLUDEPATH += \ $$PWD \ ../cpp/