http://code.google.com/p/googletest/wiki/Primer
Simple test case
#include <gtest/gtest.h>
TEST(TestSuite, TestCase1)
{
ASSERT_TRUE(expr);
}
TEST(TestSuite, TestCase2)
{
ASSERT_TRUE(expr);
}
Get the main function for free
Link gtest_main.cc and you get RUN_ALL_TESTS free
What to do if a test fails
Abort the test on expression failure:
ASSERT_TRUE(expr);
Continue the test on expression failure:
EXPECT_TRUE(expr);
Floating point comparison:
ASSERT_FLOAT_EQ(val1, val2);
ASSERT_DOUBLE_EQ(val1, val2);
ASSERT_NEAR(val1, val2, epsilon);
EXPECT_FLOAT_EQ(val1, val2);
EXPECT_DOUBLE_EQ(val1, val2);
EXPECT_NEAR(val1, val2, epsilon);
Repeat tests (useful for finding subtle race conditions)
--gtest_repeat=1000
Enter the debugger upon test failure
--gtest_break_on_failure
Generate an xml report "foobar.xml"
--gtest_output="xml:foobar"
Only run some tests
--gtest_filter=TestSuite* // runs all suites matching TestSuite*
--gtest_filter=TestSuite*-*.*2 // runs all suites matching TestSuite* except cases ending in '2'
--gtest_filter=Foo*:Bar* // separate different reg-ex's with ':'
No comments:
Post a Comment