googletest

Simplest example of using Google C++ Testing Framework with CMake

谁说我不能喝 提交于 2019-12-02 16:56:52
I have a very simple C++ library (one header file, one .cpp file). I want to write unit tests for this project using the Google C++ Testing Framework. Here is the directory structure: ~/project1 | |-- project1.cpp |-- project1.h |-- project1_unittests.cpp \-- CMakeLists.txt I do not plan to write my own main() function. I want to link with gtest_main as mentioned in the primer . What should CMakeLists.txt contain? Enable CMake's built-in testing subsystem: # For make-based builds, defines make target named test. # For Visual Studio builds, defines Visual Studio project named RUN_TESTS. enable

How to clone and integrate external (from git) cmake project into local one

元气小坏坏 提交于 2019-12-02 16:52:25
I faced with a problem when I was trying to use Google Test. There are lot of manuals on how to use ExternalProject_Add for the adding gtest into the project, however most of these describe a method based on downloading zip archive with gtest and build it. As we know gtest is github-hosted and cmake-based project. So I'd like to find native cmake way. If this would be a header-only project, I'd write something like: cmake_minimum_required(VERSION 2.8.8) include(ExternalProject) find_package(Git REQUIRED) ExternalProject_Add( gtest PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/ext GIT_REPOSITORY https:/

Setup Google test in CLion

放肆的年华 提交于 2019-12-02 16:12:35
I have been sitting online for hours already trying to setup Google test on Clion in Linux but have not been able to find anything. Can someone guide me with setting this up please? Dornathal Create new Project Create a repository in my ClionProjects folder cd ~/ClionProjects mkdir .repo cd .repo Clone the DownloadProject from github git clone https://github.com/Crascit/DownloadProject.git Create a C++ project with a src and test directory Add following files: CMakeLists.txt cmake_minimum_required(VERSION 3.3) project(MyProjectName) add_subdirectory(src) add_subdirectory(test) src/CMakeLists

Google Test in Visual Studio 2012

被刻印的时光 ゝ 提交于 2019-12-02 16:05:57
I am trying to get started with unit testing. I downloaded the latest build of gtest, and extracted it to A:\gtest As the instructions specified, I opened gtest.sln. Visual studio only allows me to open the sln if I agree to update it. Then when I try to build I get a pile of errors: 1>------ Build started: Project: gtest, Configuration: Debug Win32 ------ 1> gtest-all.cc 1>a:\gtest\include\gtest\gtest-printers.h(550): error C2977: 'std::tuple' : too many template arguments 1> b:\program files (x86)\microsoft visual studio 2012\vc\include\utility(73) : see declaration of 'std::tuple' 1>a:

How to make compiler generate a “elf32-x86-64” format object file?

回眸只為那壹抹淺笑 提交于 2019-12-02 15:53:48
问题 First, some background info about elf32-x86-64 format. It is a format that leverages 64-bit hardware while enforcing 32-bit pointers. Ref1 and Ref2. Question I am trying to link the Google Test framework binaries to my project. I use objdump -f to check the format of Google Test binaries and my binaries. Google Test format is elf64-x86-64 . Mine elf32-x86-64 . So they cannot be linked together. Then I add below content to the google test's internal_utils.cmake file: set(ZEPHYR_LINK_FLAGS "-Wl

Boost Test Vs Google Test Framework

旧街凉风 提交于 2019-12-02 15:31:08
I am new to Unit Testing world, basically I am c++ developer working on a large product for almost 3 years, and now I've decided to perform automated unit testing of my code. For this I do lot of research on the internet and came across many tools and frameworks and finally chose the following two: 1) Boost Test Libraries 2) Google Test Framework for c++ Now I am confused as to which to choose from those. If someone uses any of the above then please share your experience. Aravind R. Yarram The below SO posts pretty much answer your questions Comparison of c++ unit test frameworks Unit testing

How to send custom message in Google C++ Testing Framework?

醉酒当歌 提交于 2019-12-02 14:11:37
I use Google C++ Testing Framework for unit testing of my code. I use Eclipse CDT with C++ Unit testing module for output analysis. Previously I used CppUnit it has macros family CPPUNIT*_MESSAGE that could be called like this: CPPUNIT_ASSERT_EQUAL_MESSAGE("message",EXPECTED_VALUE,ACTUAL_VALUE) And allows to send custom messages to test output. Is there a way to include some custom text in google test output? (Preferably the way that could include message to data that is read by existing programs for automated unit testing using google test.) The gtest macros return a stream for outputting

Confusion about unit tests (googletest) and projects/folder/files

雨燕双飞 提交于 2019-12-02 11:50:49
问题 It's the first time I want to use unit tests in my c++ project. Hence I've many existing classes for which I will write tests (at least for some of them). Further, the application has of course a main() function. I'm using qt creator with qmake but could also switch to cmake. The project, qt creator and qmake are working nicely. My confusion is now how do I add unit test? I intent to use googletest. I've already run a test in a new project, testing some dummy add(int, int) function, with

how to use a .c file to write a test class in google test instead of .cpp file?

冷暖自知 提交于 2019-12-02 11:43:48
I have used googletest for my Android NDK project contain .c files. I have used a test class of the type .cpp to do the same. I want to use .c file instead. I get the following error when I try to use it : Running main() from gtest_main.cc [==========] Running 0 tests from 0 test cases. [==========] 0 tests from 0 test cases ran. (1 ms total) [ PASSED ] 0 tests. How can i solve this? Mike Kinghan You cannot use a .c file to write a test class in googletest instead of a .cpp file. A .c file should contain C language source code and a C/C++ compiler will assume that a .c file is to be compiled

GoogleTest CMake doesn't recognize TEST_F: Like it's not recognizing GTest something

久未见 提交于 2019-12-02 10:58:02
问题 OK, I admit it, this is a unique case. When we build our application we are using make, so I've included my tests in a test folder under src. Then at the same level as our release folder we have created a unit-test folder that includes all of our source files and our test source files. But my IDE is CLion, which uses CMake. In my CMakeLists.txt file, I have included: enable_testing() find_package(GTest REQUIRED) include_directories(${GTEST_INCLUDE_DIRS}) add_executable(TestProject ${SOURCE