c++ - netbeans c++ googletest 从 gui 运行测试

标签 c++ ubuntu netbeans cmake googletest

所以我在 ubuntu 14.04 上运行了 NetBeans 8.1。我有一个使用 CMakeLists 文件和 googletest 的现有项目。我正在尝试设置它并运行它。所以我安装了 NBCndUnit,然后按照此处的说明进行操作:https://github.com/offa/NBCndUnit/wiki/Using-existing-projects#a-workaround-for-cmake . 这是我的项目/CMakeLists 文件的一部分:

cmake_policy(SET CMP0037 OLD)
add_custom_target(build-tests COMMENT "starting build-tests target" )
add_custom_target(test myAppTest COMMENT "starting test target")

这是我的 myApp/test CMakeLists 文件的一部分:

add_executable(myAppTest ${SOURCES} ${HEADERS})

target_link_libraries(myAppTest 
    -L${GTEST_LIBRARY_DIR} 
    -L${GMOCK_LIBRARY_DIR}
    myApp
    gtest
    gmock
    # other dependencies
)

add_test(myAppTest myAppTest )

当我右键单击主项目 CMakeLists.txt 文件并选择“生成 makefile”时 - 它成功了。当我右键单击 Makefile 并转到 Make Target 子菜单时,我可以选择几个目标:

  • 全部
  • 清洁
  • 帮助
  • 构建测试
  • 测试

当我选择例如。 “build-tests”目标——没有任何反应(这是预期的,因为这个目标是空的):

cd '(some project path)/cmake_build'
/usr/bin/make  -f Makefile build-tests
Built target build-tests

如果我选择“测试”目标 - 它被构建并执行(在控制台窗口中输出)

cd '(path to project)/cmake_build'
/usr/bin/make  -f Makefile test
[ 34%] Built target dependency1
[ 54%] Built target dependency2
[ 82%] Built target dependency3
[ 88%] Built target dependency4
[ 97%] Built target dependency5
[100%] starting test target
[==========] Running 111 tests from 7 test cases.
[----------] Global test environment set-up.
[----------] 1 test from Foo
[ RUN      ] Foo.Bar
[       OK ] Foo.Bar (0 ms)
[----------] 1 test from Foo (0 ms total)
(rest of gtest output)

但我想在 Netbeans TestResults 窗口 Pane 中查看测试结果。所以我转到菜单中的“运行”->“测试项目”命令。这里出现了一个问题:一个新的选项卡被添加到输出 Pane ,它的标题是 myApp(Build, Build Tests...)。它会尝试构建整个项目:

cd '(project path)/cmake_build'
/usr/bin/make -j4 -f Makefile

问题是,由于依赖关系,整个项目还不能构建。所有必要的都在 myAppTest 中模拟(并且测试本身是可运行的 - 例如,通过从 makefile 上下文菜单构建“测试”目标)。所以真正的问题是: 我可以在构建和运行实际测试之前以某种方式跳过构建整个项目吗?

最佳答案

Can I somehow skip building whole project before bulding and running the actual tests?

Netbeans 默认构建所有 目标。我猜这在某种程度上是集成的。一种认为您可以尝试的方法是从该默认目标中排除对象/目标。

另一种方法:添加一个选项(例如,BUILD_TESTS_ONLY)仅构建运行测试所需的部分。默认情况下可以关闭此选项,因此它不会破坏任何其他构建。

关于c++ - netbeans c++ googletest 从 gui 运行测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39704606/

相关文章:

c++ - 在不使用专用计数器的情况下检查 QTextStream 读取的总行数

c++ - 我编写了以下代码来读取C++中的矩阵,然后打印其行和列。我收到此错误

ubuntu - 需要帮助在 Ubuntu 上安装 Shopware6

java - 如何从java源代码中获取类、voids等的依赖关系?

java - 我应该将其他组件(例如 .mdb)放在 Netbeans 项目中的哪里

cordova - Netbeans 从现有源创建/导入cordova 项目

c++ - 输入/输出从命令行可执行文件重定向到文件

ubuntu - 如何使用 Chef 设置/更改主机名?

bash - 如何在 bash 中的多字符定界符上拆分字符串?

C++,如果我需要它,我是否应该#include *和*它包含的其他东西?