svn checkout ....
configure
make
make install
默认装在 /usr/local/include /usr/local/lib 下
有两个库 libgtest 和 libgtest_main
使用时 gcc -I.. -L... -l... .................
------------------------------------------------------------------------
Once you are able to compile the Google Test library, you should create a
project or build target for your test program. Make sure you have
GTEST_ROOT/include
in the header search path so that the compiler can find
when compiling your test. Set up your test project to link with the
Google Test library
test program -> test cases -> tests
ASSERT_*
EXPECT_*
<<
ASSERT_EQ(expected, actual); the arguments' evaluation order is undefined (i.e. the compiler is free
to choose any order) and your code should not depend on any particular
argument evaluation order.
ASSERT_EQ() does pointer equality on pointers. If used on two C
strings, it tests if they are in the same memory location, not if they
have the same value. Therefore, if you want to compare C strings (e.g.
const
char*) by value, use
ASSERT_STREQ() , which will be
described later on. In particular, to assert that a C string is
NULL,
use
ASSERT_STREQ(NULL, c_string) . However, to compare two
string
objects, you should use
ASSERT_EQ.
TEST(test_case_name, test_name) {
... test body ...
}
fixtures:
class Footest : public ::testing::test
TEST_F(test_case_name, test_name) {
... test body ...
}
The ::testing::InitGoogleTest() function parses the command
line for Google Test flags, and removes all recognized flags. This
allows the user to control a test program's behavior via various flags,
which we'll cover in .
You must call this function before calling RUN_ALL_TESTS(), or
the flags won't be properly initialized.
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
gtest_main library
---------------------------------------------------
advanced guide:
:
SUCCEED();
FAIL();
ADD_FAILURE();
Fatal
assertion | Nonfatal assertion | Verifies
|
ASSERT_THROW(statement, exception_type);
| EXPECT_THROW(statement,
exception_type); | statement throws an exception
of the given type |
ASSERT_ANY_THROW(statement);
| EXPECT_ANY_THROW(statement);
| statement throws an exception of any type |
ASSERT_NO_THROW(statement);
| EXPECT_NO_THROW(statement);
| statement doesn't throw any exception |
阅读(690) | 评论(0) | 转发(0) |