Problems with cmake, gtest and auto test plugin



  • I have tried several things but I always get 0 passes 0 failed even I select debug&run test with or without deployment there is no effect. is this a bug or what should I do?0_1490603071551_Screenshot_2017-03-27_11-20-06.png


  • Lifetime Qt Champion

    Hi,

    You need to give more details about your project, what exactly fails, what version of Qt you are using, platform etc.


  • Moderators

    @V.-B.-Macit I have used make test with cmake and testing using google test. I have not used the auto test plugin, but the rest should work.

    Maybe share your CMakeLists.txt and exactly what you are doing and what results you expect versus what results you get.



  • The project is created with autotest. The code is the default one.

    // tst_test_example.h

    #include <gtest/gtest.h>
    #include <gmock/gmock-matchers.h>
    
    using namespace testing;
    
    TEST(test_example, FirstTest)
    {
        EXPECT_EQ(1, 1);
        ASSERT_THAT(0, Eq(0));
    }
    
    

    // main.cpp

    #include "tst_test_example.h"
    #include <gtest/gtest.h>
    
    int main(int argc, char *argv[])
    {
        ::testing::InitGoogleTest(&argc, argv);
        return RUN_ALL_TESTS();
    }
    

    CMakeLists.txt

    CMAKE_MINIMUM_REQUIRED(VERSION 3.1)
    
    PROJECT(test_example
            LANGUAGES CXX)
    
    find_package(Threads REQUIRED)
    
    if ($ENV{GOOGLETEST_DIR})
        SET(GOOGLETEST_DIR $ENV{GOOGLETEST_DIR})
    else ()
        message(WARNING "Using googletest src dir specified at Qt Creator wizard")
        SET(GOOGLETEST_DIR "/home/aburov/Projects/3rd/googletest")
    endif ()
    if (EXISTS ${GOOGLETEST_DIR})
        SET(GTestSrc ${GOOGLETEST_DIR}/googletest)
        SET(GMockSrc ${GOOGLETEST_DIR}/googlemock)
    else ()
        message( FATAL_ERROR "No googletest src dir found - set GOOGLETEST_DIR to enable!")
    endif ()
    
    include_directories(${GTestSrc} ${GTestSrc}/include ${GMockSrc} ${GMockSrc}/include)
    
    add_executable(${PROJECT_NAME} main.cpp tst_test_example.h
                   ${GTestSrc}/src/gtest-all.cc
                   ${GMockSrc}/src/gmock-all.cc)
    add_test(${PROJECT_NAME} COMMAND ${PROJECT_NAME})
    target_link_libraries(${PROJECT_NAME} PRIVATE Threads::Threads)
    

    Here is the result of running (successful)
    alt text
    image

    But when run via Tools->Tests->Run All Tests
    alt text
    image


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.