简体   繁体   English

netbeans c ++ googletest从gui运行测试

[英]netbeans c++ googletest run tests from gui

So I have NetBeans 8.1 running on ubuntu 14.04. 所以我在ubuntu 14.04上运行了NetBeans 8.1。 I have an existing project using CMakeLists files as well as googletest. 我有一个使用CMakeLists文件以及googletest的现有项目。 I am trying to set it up and runnig. 我正在尝试设置它并运行。 So I installed the NBCndUnit, and then followed instructions found here: https://github.com/offa/NBCndUnit/wiki/Using-existing-projects#a-workaround-for-cmake . 因此,我安装了NBCndUnit,然后按照此处的说明进行操作: https : //github.com/offa/NBCndUnit/wiki/Using-existing-projects#a-workaround-for-cmake here's part of my project/CMakeLists file: 这是我的project / 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")

and here's the part of my myApp/test CMakeLists file: 这是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 )

when I right click on the main project CMakeLists.txt file and choose "generate makefile" - it succeeds. 当我右键单击主项目CMakeLists.txt文件并选择“生成makefile”时-成功。 When I then right click on the Makefile and go to Make Target submenu, I can choose several targets: 然后,当我右键单击Makefile并转到Make Target子菜单时,我可以选择几个目标:

  • all 所有
  • clean 清洁
  • help 救命
  • build-tests 建立检验
  • test 测试

When I then choose eg. 当我然后选择例如。 "build-tests" target - nothing happens (which is expected, as this target is empty): “构建测试”目标-没有任何反应(这是预期的,因为此目标为空):

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

If i choose "test" target - it gets built and executed (output in the console window) 如果我选择“测试”目标-它会生成并执行(控制台窗口中的输出)

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)

But I would like to see the test results in Netbeans TestResults window pane. 但是我想在Netbeans TestResults窗口窗格中查看测试结果。 So I go to the 'Run'->'Test project' command in the menu. 因此,我转到菜单中的“运行”->“测试项目”命令。 And here a problem appears: A new tab is added to the Output pane, it is titled myApp(Build, Build Tests...). 此处出现一个问题:在“输出”窗格中添加了一个新选项卡,其标题为myApp(Build,Build Tests ...)。 And it tries to build the whole project: 然后尝试构建整个项目:

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

the problem is, that the whole project is not yet buildable, due to dependencies. 问题在于,由于依赖关系,整个项目尚无法构建。 All that is necessary is mocked in the myAppTest (and the test themselves are runable - eg. by building the "test" target from makefile context menu). 所需的所有操作都在myAppTest中进行了模拟(并且测试本身是可运行的-例如,通过从makefile上下文菜单构建“ test”目标)。 So the real question is: Can I somehow skip building whole project before bulding and running the actual tests? 因此,真正的问题是:在构建和运行实际测试之前,我能以某种方式跳过构建整个项目吗?

Can I somehow skip building whole project before bulding and running the actual tests? 在构建和运行实际测试之前,我可以以某种方式跳过构建整个项目吗?

Netbeans builds all targets by default. Netbeans默认情况下会构建all目标。 This is somehow integrated I guess. 我猜这是某种程度的集成。 One think you can try is to exclude the objects / targets from this default target. 您可以尝试的一种方法是从此默认目标中排除对象/目标。

Another way to go: Add an option which (eg. BUILD_TESTS_ONLY ) which builds only the parts needed to run the tests. 还有另一种方法:添加一个选项(例如BUILD_TESTS_ONLY ),该选项仅构建运行测试所需的零件。 This option can be off by default so it doesn't break any other builds. 此选项默认情况下可以关闭,因此不会破坏其他任何版本。

well, i was partially able to sovle my problem. 好吧,我部分能够解决我的问题。 what i did, is to add custom project properties configuration scheme: 我所做的是添加自定义项目属性配置方案: 在此处输入图片说明

I simply added some fake build target ( build_tests ), so NB builds it instead of the default all target. 我只是添加了一些虚假的构建目标( build_tests ),所以NB会构建它,而不是默认的all目标。 Kind of hacky, but does what I need. 有点hacky,但是可以满足我的需求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM