Giter Site home page Giter Site logo

raleighlittles / minimal-gtest-example Goto Github PK

View Code? Open in Web Editor NEW
4.0 2.0 0.0 199 KB

A very very minimal example of how to configure and run GTest, Google's C++ testing framework.

Home Page: https://github.com/google/googletest

CMake 22.13% C 28.60% C++ 37.82% Makefile 11.44%
gtest cpp cmakelists cmake-examples unit-testing-framework google-test ubuntu

minimal-gtest-example's Introduction

About

This is a very simple example of how to run GTest (Google Test) on a Ubuntu 16+ machine.

For more information about Google Test, check out the official Google Test Repo and specifically, the GTest Primer.

Instructions

Installing GTest onto your system

  • Start by installing libgtest-dev:
sudo apt-get install libgtest-dev
  • Navigate to where the files were installed, which is usually: /usr/src/gtest/ if you installed them using the command above.
cd /usr/src/gtest/
  • Use C-Make to create the build files.
sudo cmake CMakeLists.txt
  • Once the build and makefiles are created you can just run:
sudo make
  • Copy the newly-built library into your libraries folder, which for Ubuntu is /usr/lib/.
sudo cp *.a /usr/lib/

Running GTest

To truly make this example minimal, we'll only use 2 files: a source code file and a test file.

  • fake_class.hpp is a source file that contains two methods.
  • fake_class_tests.cpp contains tests for those methods.

Building an executable

Once you have your two files, all that is needed is to build them together. All modern C++ IDEs support auto-generating Makefiles/CMake files but if yours does not, then you can use the one provided.

This means you can simply just run:

cmake CMakeLists.txt

and then

make 

to create your executable

CMake Users: If you would like to use your own custom CMakeFile, then at the very least it must include the following lines to be able to use GTest:

find_package(GTest REQUIRED)
include_directories($(GTEST_INCLUDE_DIRS))
target_link_libraries(<projects-executable-name> $(GTEST_LIBRARIES) pthread)

Finally running the tests

Once the executable is built, you can simply run it.

./gtest_example

(if using the provided CMakeLists.txt file)

For more information about Google Test, check out the official Google Test Repo.

If all went well, you should see


[PASSED] 2 tests.

At the bottom.

minimal-gtest-example's People

Contributors

raleighlittles avatar ralittles avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.