c++ - Unit testing with google test -
i want larn using google test framework everyday projects, looked few tutorials, have no thought how started.
i'm using qtcreator in ubuntu 14.04, downloaded gtest.zip google site , unzipped it, here stoped.
this code want "gtest":
//main.cpp #include <iostream> #include <cstdlib> #include "fib.h" using namespace std; int main(int argc, char *argv[]) { int n = atof(argv[1]); fib fibnumber; cout << "\ndesired number is: " << fibnumber.fibrec(n) << endl; } //fib.h #ifndef fib_h #define fib_h class fib { public: int fibrec(int n); }; #endif // fib_h //fib.cpp #include "fib.h" int fib::fibrec(int n) { if(n <= 0) homecoming 0; if(n == 1) homecoming 1; else return(fibrec(n-1)+fibrec(n-2)); }
so begin, want create unit test , compile without plugins, don't know how create utilize of file unzipped , utilize write unit test.
the google testing framework works building part of source code. means there no library have link to, instead build library when compile code (there reason this).
have @ official documentation: https://code.google.com/p/googletest/wiki/primer
stepstry build test testcase program. can't tell how qtcreator should easy plenty find. create test fail, 1 below.
test(myfirsttest, thistestshallfail) { expect_eq(1, 2); }
run simple test check fails. if want, alter create pass.
start creating unit tests. check few easy number. check boundary conditions etc.
c++ unit-testing googletest
No comments:
Post a Comment