【发布时间】:2014-04-04 02:54:25
【问题描述】:
我无法启动和运行 Google 测试。我已经阅读了 Google 推荐的 steps,我还查看了以前的 post,并阅读了其他一些 examples,但并没有弄清楚很多事情。
为了简单起见,我正在尝试来自 Google 测试的建议示例,该示例可从 Android ndk 中的目录 - sample1 中获得:
// main.cpp
#include <QtGui/QGuiApplication>
#include "qtquick2applicationviewer.h"
#include "gtest/gtest.h"
int main(int argc, char *argv[])
{
QGuiApplication app(argc, argv);
testing::InitGoogleTest(&argc, argv);
QtQuick2ApplicationViewer viewer;
viewer.setMainQmlFile(QStringLiteral("qml/factorial/main.qml"));
viewer.showExpanded();
return RUN_ALL_TESTS();
}
// sample1_unittest.cpp
#include <limits.h>
#include "sample1.h"
#include "gtest/gtest.h"
// Tests factorial of 0.
TEST(FactorialTest, Zero) {
EXPECT_EQ(1, Factorial(0));
}
文件 sample1.h、sample1.cpp 也在项目中,其中包含阶乘函数。谷歌测试同样获知项目文件——factorial.pro:
INCLUDEPATH +=
/opt/android-studio/ndk/sources/third_party/googletest/googletest/include
当我按下 [Build > Build Project "factorial"] 时,会出现以下错误:
main.cpp:8: error: undefined reference to 'testing::InitGoogleTest(int*, char**)'
sample1_unittest.cpp:17: error: undefined reference to 'testing::Test::Test()'
我正在使用 Ubuntu、QtCreator、Android 和 C++。事实上,我已经花了 3 天的时间在周围嘲笑,但到目前为止没有得到太多。因此,我在这里发帖希望一些大师可以对此提供任何提示。任何帮助将不胜感激。
【问题讨论】:
-
您是否已将 gtest.lib\gtest.a 添加到您的链接行?
-
@Wes - 刚刚做了:# find / -name gtest.a ... 没有任何结果。有什么建议应该在哪里,还是应该构建 gtest.a?谢谢!
-
请注意,Google 建议您不要构建库,而是将 GTest 代码包含到您的项目中。见code.google.com/p/googletest/wiki/…
标签: android c++ unit-testing android-ndk qt-creator