gtest

1. Download googletest, which contain googletest and googlemockhtml

: https://github.com/google/googletestgit

2. install both googletest and googlemockgithub

cd googletest/build
cmake ..
sudo make install

It is expected that both gtest and gmock have been installed in /usr/local/ui

 

3. google

square.h spa

#include <math.h>

double squareroot (const double aa)
{
    return sqrt(aa);
}

test.cppcode

#include "square.h"
#include "gtest/gtest.h"

TEST (SquareRootTest, PositiveNos) { 
    EXPECT_EQ (18.0, squareroot (324.0));
}
 
TEST (SquareRootTest, ZeroAndNegativeNos) { 
    ASSERT_EQ (0.0, squareroot (0.0));
}

int main(int argc, char **argv) {
  ::testing::InitGoogleTest(&argc, argv);
  return RUN_ALL_TESTS();
}

 

g++ -pthread  ./test.cpp /usr/local/lib/libgtest.a -o test

 

Reference:htm

google/googletest, gitblog

A quick introduction to the Google C++ Testing Framework, IBMget

相關文章
相關標籤/搜索