我正在尝试使用QT Creator进行单元测试。我尝试使用linux进行操作,它确实运行良好,但是当我开始在Windows中进行操作时。我发现设置与我对Linux所做的方式有所不同。
现在在我的Windows QT Creator中,我已经为我的项目设置了gtest。一切正常,直到我开始设置googlemock。有人可以告诉我如何在QT Creator中设置googlemock吗? (Windows)
我在.pro文件的源代码中添加了一些gmock文件,就像我对gtest文件所做的一样。另外,我已经添加了一些库,例如libgmock.a和libgmock_main.a。
这是问题结果Qt的图像
INCLUDEPATH += "gtest/include/"
INCLUDEPATH += "gtest/"
INCLUDEPATH += "../../"
INCLUDEPATH += "gmock/include/gmock/"
INCLUDEPATH += "gmock/include/"
INCLUDEPATH += "gmock/"
INCLUDEPATH += "../../"
FORMS += \
../calculator.ui
HEADERS += \
../calculator.h \
../button.h
SOURCES += \
../calculator.cpp \
../button.cpp \
main.cpp \
gtest/src/gtest-typed-test.cc \
gtest/src/gtest-test-part.cc \
gtest/src/gtest-printers.cc \
gtest/src/gtest-port.cc \
gtest/src/gtest-filepath.cc \
gtest/src/gtest-death-test.cc \
gtest/src/gtest-all.cc \
gtest/src/gtest.cc \
gmock/src/gmock-spec-builders.cc \
gmock/src/gmock-matchers.cc \
gmock/src/gmock-cardinalities.cc \
gmock/src/gmock-all.cc \
gmock/src/gmock.cc \
gmock/src/gmock-internal-utils.cc
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../Gmock_lib/ -lgmock_main
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../Gmock_lib/ -lgmock_maind
else:unix: LIBS += -L$$PWD/../../../Gmock_lib/ -lgmock_main
INCLUDEPATH += $$PWD/../../../Gmock_lib
DEPENDPATH += $$PWD/../../../Gmock_lib
win32:CONFIG(release, debug|release): LIBS += -L$$PWD/../../../Gmock_lib/ -lgmock
else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/../../../Gmock_lib/ -lgmockd
else:unix: LIBS += -L$$PWD/../../../Gmock_lib/ -lgmock
INCLUDEPATH += $$PWD/../../../Gmock_lib
DEPENDPATH += $$PWD/../../../Gmock_lib
main.cpp
#include <gtest/gtest.h>
#include <QApplication>
#include "Calculator/calculator.h"
#include "Calculator/button.h"
#include "Calculator/calculator.h"
#include <gmock/gmock.h>
TEST (sumInMemory, clearMemoryF) {
calculator cal;
double x = cal.sumInMemory;
EXPECT_EQ( x , 0.0);
}
TEST (functionTest, Subtest1) {
calculator cal;
int x = cal.equalClicked();
EXPECT_NE( x , -1);
}
TEST (functionTest, Subtest2) {
calculator cal;
double x = cal.factorSoFar;
EXPECT_EQ( x , 0.0);
}
int main (int argc, char *argv[])
{
QApplication a(argc, argv);
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
答案 0 :(得分:1)
我遇到了同样的问题,建议您下载其他版本的gmock。就我而言,我使用gmock 1.7.0。一些旧版本有一些问题/问题。只需遵循编译器对您说的话即可。
一次修复错误
答案 1 :(得分:1)
我的新.pro文件
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
CONFIG += console c++14
INCLUDEPATH += "gmock/include/"
INCLUDEPATH += "gmock/"
INCLUDEPATH += "gtest/include/"
INCLUDEPATH += "gtest/src/"
INCLUDEPATH += "gtest/"
INCLUDEPATH += "../../"
FORMS += \
../calculator.ui
HEADERS += \
../calculator.h \
../button.h \
SOURCES += \
../calculator.cpp \
../button.cpp \
main.cpp \
gtest/src/gtest.cc \
gtest/src/gtest-all.cc \
gtest/src/gtest-death-test.cc \
gtest/src/gtest-filepath.cc \
gtest/src/gtest-port.cc \
gtest/src/gtest-printers.cc \
gtest/src/gtest-test-part.cc \
gtest/src/gtest-typed-test.cc
我的src文件中的项目是
gmock-spec-builders.cc
gmock-matchers.cc
gmock-internal-utils.cc
gmock-cardinalities.cc
gmock-all.cc
gmock-main.cc
gmock.cc
注意:我只使用src并将ginclude和gmock用于测试文件。 我希望这对其他人有帮助