Add a google test project to run unit tests on local PC

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Add a google test project to run unit tests on local PC

Jump to solution
4,005 Views
bp1979
Senior Contributor I

Dear NXP forum,

I am writing a project in MCU Xpresso (for an imx rt1020 chip, but I don't think that's really relevant for my question).

I am looking for a not too complicated way to add a project, which compiles the software for my local PC and runs unit tests written with google test framework.

I am running MCU expresso on windows (on a amd ryzen processor if that matters). 

Is there a somewhat more extensive guide available somewhere which i can follow? Can I add a "normal C++ project" to my workspace? Should I install some additional plugins? Should I get cygwin gcc compiler? How do I configure that? 

I tried to google, fantasizing that tons of people already did this before me and that I could simply steal their brilliant solutions, but unfortunately there  is not that much  to copy  from yet

Many thanks in advance!

0 Kudos
1 Solution
3,978 Views
bp1979
Senior Contributor I

Found it out eventually...

- git clone https://github.com/google/googletest.git -b release-1.11.0

- install mingw from MSYS2 (MinGW-w64 fails to compile std::mutex for reasons I forgot, but MSYS2 works flawless).

- add "C:\msys64\mingw64\bin" to your path.

- restart eclipse (so that it will find the gcc compiler)

- create new C++ project 

  • file - new -  project
  • C++  project
  • empty project
  • toolchain should show MinGW GCC as well, make sure to select that

Then open project properties

- added include paths to:

  • googletest
  • googletest/includes
  • googlemock
  • googlemock/includes

- added source location to:

  • googletest/src
  • googlemock/src

Now the last part took me long enough. After compiling, I got 1000+ link errors.  This has something to do with the possibility to "fuse"  googletest into your own code. For that purpose there is a file called

googletest/src/gtest-all.cc

This file includes all gtest  source files in 1 source file. Since I just added the entire src folder as source location, I effectively compile the same source files twice, which  obviously give the link errors.  

So  after deleting gtest-all.cc from disk, all works fine.

View solution in original post

0 Kudos
6 Replies
1,098 Views
EhsanElahi
Contributor I

Hi Experts,

I am new with MCUXpresso and its unit testing. I have a question related to unit testing. Why MCUXpresso use unity test framework instead of Google test framework.?

0 Kudos
1,086 Views
ErichStyger
Senior Contributor V

You are of course free to use any test framework you want to use, there is no limitation on this.

I'm using unity for my testing, mainly because it is very easy to use (just 1 source file and 3 header files), and nicely can be used for embedded targets too.

Again: use what you think is best for you.

0 Kudos
1,081 Views
EhsanElahi
Contributor I

I tried with gtest and unity test frameworks. Unity test framework is integrated smoothly with MCUXpresso and Gtest gives an error of compiler.

 

CMake Error at _deps/googletest-src/googletest/cmake/internal_utils.cmake:200 (target_compile_features):
target_compile_features no known features for CXX compiler

"GNU"

version 8.2.1.
Call Stack (most recent call first):
_deps/googletest-src/googletest/cmake/internal_utils.cmake:213 (cxx_library_with_type)
_deps/googletest-src/googletest/CMakeLists.txt:126 (cxx_library)

0 Kudos
3,986 Views
ZhangJennie
NXP TechSupport
NXP TechSupport

Hi

MCUXpresso IDE is based on Eclipses and it is installed with some Eclipse plugins. Unfortunately there is no google test framework included.

The IDE can be further enhanced with many other Eclipse plugins by user but we don't have extension manual for google test framework. 

I performed search and find some info. for example

https://www.codeproject.com/Articles/811934/Cplusplus-unit-test-start-guide-how-to-set-up-Goog

https://github.com/xgsa/cdt-tests-runner/wiki/Tutorial

This question is more about eclipse rather than MCUXpresso itself. If someone have experience on this, just feel free to leave comment.

Jun Zhang

 

1,081 Views
EhsanElahi
Contributor I
I tried with gtest and unity test frameworks. Unity test framework is integrated smoothly with MCUXpresso and Gtest gives an error of compiler.

CMake Error at _deps/googletest-src/googletest/cmake/internal_utils.cmake:200 (target_compile_features):
target_compile_features no known features for CXX compiler

"GNU"

version 8.2.1.
Call Stack (most recent call first):
_deps/googletest-src/googletest/cmake/internal_utils.cmake:213 (cxx_library_with_type)
_deps/googletest-src/googletest/CMakeLists.txt:126 (cxx_library)
0 Kudos
3,979 Views
bp1979
Senior Contributor I

Found it out eventually...

- git clone https://github.com/google/googletest.git -b release-1.11.0

- install mingw from MSYS2 (MinGW-w64 fails to compile std::mutex for reasons I forgot, but MSYS2 works flawless).

- add "C:\msys64\mingw64\bin" to your path.

- restart eclipse (so that it will find the gcc compiler)

- create new C++ project 

  • file - new -  project
  • C++  project
  • empty project
  • toolchain should show MinGW GCC as well, make sure to select that

Then open project properties

- added include paths to:

  • googletest
  • googletest/includes
  • googlemock
  • googlemock/includes

- added source location to:

  • googletest/src
  • googlemock/src

Now the last part took me long enough. After compiling, I got 1000+ link errors.  This has something to do with the possibility to "fuse"  googletest into your own code. For that purpose there is a file called

googletest/src/gtest-all.cc

This file includes all gtest  source files in 1 source file. Since I just added the entire src folder as source location, I effectively compile the same source files twice, which  obviously give the link errors.  

So  after deleting gtest-all.cc from disk, all works fine.

0 Kudos