Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migration of unmigrated content due to installation of a new plugin

...

Code Block
languagecpp
mkdir build
cd build
cmake ..
make runUnitTests.o
./runUnitTests.o
 

5.1 Errors and fixes

Cannot find googletest

Uninitialized git submodules

This problem has many different manifestations. They include

  • cannot find MadgwickAHRS.h
  • cannot find googletest

A common error when compiling unit tests will be something in terms of cannot find googletest. That probably means you haven't initialized git submodules, so run git submodule update --init

Error: leaked mock object

As this error tells you, you have a leaked mock object, which was not deleted. There are multiple possible reasons for this:

...

Code Block
languagecpp
linenumberstrue
TEST_F(Fixture1, Test1) {
 
	Mock * ourMock = new Mock; // The mock is created (could also be in the test fixture constructor) at address 0x5634d2e8ca736700
	EXPECT_CALL(*ourMock, fun()); // We set expectations on the mock
 
	code->run1(); // We hope this calls ourMock->fun();
 
	delete ourMock; // Here, expectations on ourMock are verified and cleanup is performed. GoogleTest is happy.
 
	EXPECT_CALL(*ourMock, fun()); // OH NO! GoogleTest now again thinks 0x5634d2e8ca736700 is still active
 
} // after all cleanup, GoogleTest will report "Mock leaked at 0x5634d2e8ca736700 used in Fixture1.Test1", despite it was deleted on line 78.
 
 

Make sure you don't set EXPECT_CALLs after you delete the mock. Sometimes, they can hide in the test destructor, or in a mock destructor.

...