Questions tagged [googletest]
Google's C++ testing framework based on xUnit that runs on multiple platforms.
2,787
questions
0
votes
0
answers
31
views
How to use lcov with makefile
Introduction
Currently, I'm making a simple C project to try Googletest and coverage testing with lcov.
The repo of the project: https://github.com/MathieuSoysal/Poke-42/tree/21-add-sonarcloud
...
-1
votes
0
answers
23
views
Leaked mock object or seg fault with gtest
I've seen a few related questions on here but nothing that addresses this specific scenario. I've got a google mock object that I'm introducing as a shared pointer created by a singleton factory. ...
-1
votes
0
answers
19
views
'RUN_ALL_TESTS()' is ambiguous. How to use glog and gtest in one cmake project
I have a cmake project which uses glog.
folder structure is like
x -- tests
|
-- lib
|
-- gtest
The topmost CMakeLists.txt makes an add_subdirectory of lib in which the ...
-2
votes
0
answers
55
views
Unit testing issues of cmake and googletest [closed]
My root folder name is "Example" Here is the directory tree of my folders
├── .vscode
├── build
├── build-vscode
├── CMakeLists.txt
├── fixedpoint.cpp
├── fixedpoint.h
├── googletes
└── test
...
-1
votes
0
answers
34
views
Why running unit test with Ctest leads to segmentation fault while passes as direct run?
I have a problem with my executable file of my test.
When I run it with Ctest it gives me segmentation fault but when I run it with ./myfile_name it passes.
Compiling in specific environment caused ...
-2
votes
0
answers
26
views
MOCK_METHODn to "new" generic MOCK_METHOD gmock macros [closed]
I wondering if there is any script which changes old fashion MOCK_METHODn macros to the new ones, generic MOCK_METHOD or if I need to write it on my own?
I expect that not only me wants to rewrite it ...
-2
votes
0
answers
13
views
How to run Gtest script using Ctest and redirect the Gtest output on the terminal
I am trying to run my Gtest script using ctest.
while running ctest i observed that all the gtest output is by being stored in the
Testing/Temporary/LastLine.log file
i want my gtest success/ failure ...
-2
votes
1
answer
55
views
How can I test my test values using a common tolerance?
In the following tests, TestParticleForce succeeds, but TestParticleKineticEnergy fails if both of them are use the same precision 0.00001.
As far as I understand, EXPECT_NEAR(val1, val2, 0.00001); ...
-2
votes
0
answers
22
views
How can I add more test files in my unit test project? [duplicate]
I have two projects in my solution named LeapFrogCppOop__sln:
LeapFrogCppOop
LeapFrogCppOop__googletest
In the project LeapFrogCppOop__googletest, I have four C++ files:
pch.h
pch.cpp
header.h
...
-4
votes
0
answers
57
views
How can I make this unit test to succeed?
#include "pch.h"
#include "header.h"
LennardJones lj(Constants::EPSILON, Constants::SIGMA, Constants::KB);
TEST(TestCaseName, TestName)
{
Vec3 diatance(4.0, 4.0, 4.0);
...
-1
votes
0
answers
61
views
Unit test fails even though values are equal [duplicate]
How can I resolve the following issue?
#include "pch.h"
LennardJones lj(Constants::EPSILON, Constants::SIGMA, Constants::KB);
TEST(TestCaseName, TestName)
{
Vec3 diatance(4.0, 4.0, 4....
0
votes
1
answer
26
views
Detect assertion failures in a helper method
I would like to have a helper method in my tests that will cover some frequently executed checks. Consider this example:
void checkAsserts(int a, int b, int c) {
EXPECT_EQ(a, b);
EXPECT_GT(b, c);
...
-2
votes
1
answer
44
views
Build CLion CMake with the GoogleTest project from the terminal
I can build a CMake project with GoogleTest in CLion. But I cannot build it from terminal. I get a bunch of errors when building GoogleTest as a dependency. I also tried to build project without ...
2
votes
1
answer
34
views
EXPECT_CALL() macro dont compile when trying to throw a custom exception
I have following code test.cpp , which fails to compile ( compile using : g++ test.cpp -lgtest -lgmock -pthread -lfmt), I am getting this error:
could not convert ‘std::forward<CustomException&&...
1
vote
1
answer
20
views
CMAKE Linux Mint building gtest "/usr/bin/ld: cannot find -lThreads::Threads: No such file or directory"
CMAKE Linux Mint building gtest
/usr/bin/ld: cannot find -lThreads::Threads: No such file or directory
This is Gtest Out of the box after apt-get install libgtest-dev
works PERFECT on a slightly ...
-1
votes
0
answers
40
views
How can I write a unit test for this routine?
I want to write a unit test for the leapstep() routine.
Can you give me an idea on how to do it?
NOTE: I know how to write unit tests using GTest. That is not the issue. The issue is that I don't know ...
-1
votes
0
answers
29
views
Google test for C++ , how to run it in Android environment natively
We are developing a finance application with it core written in C++ , we are using Google Test for its unit testing, Now GooogeTest require a console to run , the same is not provided natively by ...
-1
votes
1
answer
18
views
GTest launched through colcon gets SEGFAULT
I'm using colcon to run tests for my ROS2 application.
Up until now I haven't had any problems, but now after adding a simple fixture
class ElectionTest : public ::testing::Test {
protected:
...
-1
votes
0
answers
49
views
32-bit source code for googletest framework
I use the GoogleTest version 1.7.0. source code from GitHub. The source code contains types that are based on 64-bits. I would like to have a version of googletest that is written for old compilers ...
1
vote
0
answers
43
views
New array-bounds and stringop-overflow GCC 13 warnings in spdlog+gtest program
I updated the operating system from Fedora 37 to Fedora 38, and my program started to produce new compilation warnings: array-bounds and stringop-overflow. The program depends on the libraries from ...
0
votes
0
answers
35
views
How to use GoogleTest/GoogleMock to test a hash table implementation?
I want to write unit tests using GoogleTest/GoogleMock for a hash table implementation I am writing for practice, but I don't know what the best approach would be.
Here are the hash table interfaces:
...
0
votes
1
answer
79
views
Unit testing an API
I've got the following Renderer API in a library that I'm writing:
class EXPORT Renderer {
public:
Renderer(const Renderer &) = delete;
Renderer &operator=(const Renderer &) = ...
0
votes
0
answers
40
views
How can I debug a file containing tests from Google Test built with CMake on MacOS M1
I am trying to debug my test file using Google Test, but it isn't working. My file structure is as follows:
- data-structures
- linked-lists
- tests-linked-list.cpp
- linked-list....
-1
votes
0
answers
41
views
Unable to debug tests using combination of cmake, GoogleTest and Visual Studio Code
I have followed the instructions on this site to make a c++ project with cmake and Googletest. Mostly everything works, except for one thing: I am unable to debug the tests created using VS Code.
My ...
0
votes
1
answer
44
views
I feel confused about the log output of googletest
I am learning googletest. I wrote a program as blow.
TEST(FactorialTest, Negative) {
EXPECT_EQ(add(1,1),2); // PASS
EXPECT_EQ(add(1,2),3); // PASS
}
int main(int argc,char **argv)
{
...
2
votes
1
answer
69
views
Unit testing a function with assertions
I have the following assert macro definition:
#define ASSERT_IF(expression) \
if (expression) { \
__debugbreak(); \
}
And the following function that uses the ...
0
votes
1
answer
47
views
Unit testing a function which output depends on current environment
I've got a following function that returns a plugin filename depending on current environment:
std::string Plugin::createFilename(std::string_view name, std::string_view extension) {
constexpr ...
1
vote
0
answers
47
views
Can death gtests be sped up on Linux?
Here is the death test on Linux:
#include <gmock/gmock.h>
#include <cassert>
void foo()
{
assert(false);
}
TEST(MyTestDeathTest, MyTest)
{
ASSERT_DEATH(foo(), "");
}
...
-1
votes
1
answer
55
views
Integrating Google Test with Cmake Build Error : No such file or directory Error
Hi I am using cmake to integrate Gtest and perform a test on sample C code.
I using GCC 13.2.0 x86_64-mingw32(mingw64) and VScode.
Below I have mentioned the Directory structure and root cmakelist and ...
0
votes
1
answer
83
views
Is it normal to change methods behaviour to test them?
I have a class:
class MotorControl
{
private:
IAccelStepper *motor;
IEncButton2<EB_ENCBTN> *encoder;
public:
void processEncoder();
void ...
-1
votes
1
answer
24
views
Gtest Git, Testing Git functionality using Gtest
In my app, I need to connect to some git repo and perform action based on given commit/hash of the git-repo. Code snip could be as below
func App_DoSomething(hash, file string) {
git....
0
votes
0
answers
37
views
How to suppress problems detected by Valgrind with EXPECT_DEBUG_DEATH Google test macro?
I’ve run to the problem with Google unit testing framework and valgrind interaction. When I use EXPECT_DEBUG_DEATH macro and memcheck tests code with valgrind I get massive log output.
valgrind --...
0
votes
0
answers
23
views
c++ googlemock Process finished with exit code -1073741515 (0xC0000135) [duplicate]
I want to use googletest on a c++ program, however I am getting an error, one for missing dlls. Here is my code:
#include <gtest/gtest.h>
#include <iostream>
TEST(anilib, comparison) {
...
0
votes
0
answers
53
views
how to run cmake tests in a single command instead of executing test program per test
I am currently porting a larger project from make to cmake. Everthing works fine but I have a issue/problem running a google test application. I have one test program containing about 5500 tests (a ...
0
votes
0
answers
17
views
C++ munmap_chunk error with a specific 3rd party lib
I am working with a 3rd party lib on Linux C++. Let's call it liba.so here. The environment is
CentOS Linux release 7.6.1810 (Core)
gcc 7.3.1
gtest 1.8.0
With a minimal code snippet and a quick test ...
0
votes
0
answers
46
views
How can I use google-test in Replit?
Matrix Test
#include <iostream>
#include <stdexcept>
#include <gtest\gtest.h>
class Vector {
private:
int size;
double* data;
public:
// Constructor
Vector() : ...
0
votes
0
answers
24
views
How can I include GoogleTest in a test module?
GitHub Repo
The following is the directory structure of the project:
MatrixMultiplicationProjectCpp
├───CMakeLists.txt
├───main.cpp
│
├───lib(...
0
votes
0
answers
23
views
How can I configure the following CMake project?
Configuration of CLion + CMake + GoogleTest
In the above video, the author uses the following directory structure:
The project's name is unit-testing
The unit-testing directory has three ...
0
votes
1
answer
70
views
Why would nng_dial ever hang?
I'm running into a perplexing issue with nng (EDIT and gtest) in c++. The first code block below is a simple program which creates a publisher and continuously sends messages. The second code block ...
-1
votes
1
answer
19
views
googlemock ON_CALL with SetArgPointee will not change from test case to test case
I have a TEST_F with the following:
struct _pulse thePulse;
thePulse.code = _PULSE_CODE_DISCONNECT;
ON_CALL(Mock::Mock_QnxInterface::MockQnxInterface::getInstance(), MsgReceivePulse(_, _,...
1
vote
1
answer
53
views
Error adding a git submodule with specific branch
I am trying to add googletest as a submodule to my repo
git submodule add -b v1.13.0 https://github.com/google/googletest.git external/googletest
The specific branch v1.13.0 I have mentioned to take a ...
0
votes
3
answers
83
views
Case insesitive regex match with GoogleTest's regex matchers?
Question
I am looking for how to make a regular expression case insensitive, that works with GoogleTest's regex matchers (e.g. ContainsRegex).
I have tried unsuccessfully to prefix my expressions with ...
0
votes
0
answers
25
views
way to enable/disable log printing in Gtest runs over command line
Need some way or to pass some argument over command line to enable and disable logging in Google Gtest framework so that i can enable or disable logging while running test and don't have to make ...
0
votes
0
answers
94
views
Conan installed GoogleTest undefined refence in Debug mode
I installed GoogleTest with Conan. I can compile and run tests in Release mod but Debug mod gives undefined reference errors.
CMakeLists:
# For now, we build as executable, in the future make it ...
0
votes
0
answers
44
views
Cannot Find User Header Search Paths in Xcode UI
Context
I am trying to integrate gtest into Xcode, but Xcode isn't properly linked to the gtest header files. (I can compile/execute the project by running g++ from command line, but not in Xcode)
I ...
0
votes
0
answers
188
views
Calling C++/CLI code from unmanaged C++ code
I have a C++/CLI unit test project, containing Google tests. I build this project as a dll. I am exporting the following method from the dll:
int runTests(int argc, char* argv[])
{
...
0
votes
1
answer
46
views
Including gtest header crashes templated Class Function call
i have a problem regarding including gtest header into my programm. The following code compiles as long as the gtest header is commented out, as soon as the header is pulled, the compiler throws an ...
1
vote
0
answers
70
views
gtest documentation using Doxygen on custom annotations
I am looking for the auto generation of my unit tests documentation. Specifically, I would like to use doxygen on my c++ project that scans it and looks for unit tests implemented in gtest (TEST/...
0
votes
1
answer
82
views
Is there a benefit of using EXPECT_NO_THROW in Google test?
In gtest one can use the EXPECT_NO_THROW macro to verify that an action does not throw an exception.
When the code does thrown an exception, the test case will be marked as failed.
However, if the ...
1
vote
2
answers
702
views
Changing .NET framework 4.7.2 to .NET Core 6.0 for a C++/CLI project
I have a Visual Studio C++/CLI project which contains some Google unit tests, and the configuration type of the project is Application (an executable). I am trying to build the project by changing ...