GithubHelp home page GithubHelp logo

crazybonze / cpp-gtest Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chicostate/cpp-gtest

0.0 1.0 0.0 101 KB

A simple example for writing unit tests for a C++ class using GoogleTest

Makefile 24.01% C++ 75.99%

cpp-gtest's Introduction

This is a simple example of a C++ class called Rando that has 4 functions.

A makefile is provided, but https://github.com/google/googletest must first be installed on the development environment.

Getting Started

  • Edit the Makefile and update this line to reflect where your googletest /include and /src directories are located:

GTEST_DIR = /usr/local/include/gtest

  • Save your changes to the Makefile. Check to make sure it works with the following commands:

make

./RandoTest

The output should show that all tests have passed. For this exercise, do not worry about warning messages unless they are errors

  • Once the initial tests are done, stage the changes you've made and commit them:

git add Makefile

git commit -m "Describe your changes here"

  • Open randoTest.cpp and decide which of the functions you want to work on first, isDivisible(), isPrime(), or nearestToZero(). You can read documentation on what each function is supposed to do inside rando.cpp

  • Think of a condition you need to test for the function you are working on. Write a new TEST in randoTest.cpp that tests that condition.

  • Build and run the test fixture:

make clean

make

./RandoTest

  • The test you just created should fail because the solution has not been implemented yet. Edit rando.cpp and fix the solution so it should pass the test (following the previous step again). If it still fails, you know right away that you need to fix that specific place in the code!

  • Once your test passes, stage and commit your changes with git.

  • Repeat the process until you are satisfied you have tested the function thoroughly and your solution passes all the tests. After you are done, make sure to commit your changes before you move on to the next function!

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.